user170732 user170732 - 23 days ago 5
Python Question

Waiting for a button state to change in Selenium Webdriver

I am testing a textbox and button - the user types in some information to the textbox and then hits the button - the button changes text from "Update" to "Updating" and then back to "Update" once the operation is complete.

I want Selenium to wait until the button returns back to "Update" before continuing.

I have tried various solutions using xpath here is where I am now:

self.wait.until(EC.element_to_be_clickable(By.XPATH, '//button[@id="send_data"][text()="Update"]'))


The HTML of the button is as follows:

<button id="send_data" type="button" class="btn btn-success" onclick="ChangeParam(this,'radio','freq'; return false;">Update</button>


and

<button id="send_data" type="button" class="btn btn-default" onclick="ChangeParam(this,'radio','freq'; return false;">Updating</button>


Where am I going wrong?

Answer

This is quite common issue: you should send type_of_locator, "locator_string" as tuple of arguments ((By.XPATH, "//button")), but not as two separate args (By.XPATH, "//button")

Use following code

self.wait.until(EC.element_to_be_clickable((By.XPATH,'//button[@id="send_data"][text()="Update"]')))