How to check if the user has clicked a button in Selenium? How to check if the user has clicked a button in Selenium? selenium selenium

How to check if the user has clicked a button in Selenium?


As soon as you click on submit button , I am assuming (which is highly likely) that redirection occurs.

after click on submit button , your will be redirected to a new Page which will have some contents, right?

What you have to do here :

element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((Locator, "value"))).text  

and you already know the value , which will be expected value.

Now you can assert these two value.

UPDATE :

As you have mentioned, that a table appears , now what you can do here is :

wait for visibility of table and get the heading of table using .text and assert the value.


I've been through a similar problem a time ago, but in my case the page could load 2 different templates without reloading, sometimes a table was displayed and sometimes a modal telling something like "there is no data"

So I couldn't search for a new element that would appear on the page, my solution was to insert my own element (via javascript) on the page whenever the user clicked at the button and then search for this new element.

Here is an example:

from selenium.webdriver.support import expected_conditions as ECfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.common.by import By# first you need to get your button at python to inject the javascriptelement = driver.find_element_by_xpath("element_xpath")# here is a sample of an element you can create via js (this one is a hidden input)javascript = "let element = arguments[0];\              element.addEventListener('click', function() { \                    let input = document.createElement('input'); \                    input.setAttribute('type', 'hidden');  \                    input.setAttribute('id', 'my_input'); \                    document.body.appendChild(input); \              });"                                    # finally you send the javascript to your webbrowser with execute_scriptdriver.execute_script(javascript,element)# then you will be able to wait the element to be created #(30 is te timeout in seconds, you should adjust as you need)hiddenInput = WebDriverWait(driver, 30).until(EC.presence_of_element_located(            (By.XPATH, '//*[@id="my_input"]'))