Website form select is disabled until the previous form has been completed.It takes some time for website to recognize the fill out. I try to use wait.until(EC.element_to_be_clickable((By.ID, "..."))), but it returns me a time exception error. I tried sleep(2), and it works. I am wondering if I can still use wait in this case.
1 Answer
You question isn't clear. You should show what you have tried/accomplished so far in detail. However, from what I understand I will try to answer you question in general.
To wait for an element to be clickable the correct syntax would be:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 30).until(
EC.element_to_be_clickable((By.ID, "ID_of_the_element")));
element.click();
In this case I have used ID as the element locator. You can use others such as XPATH as well.
Hope the helps.
4 Comments
Yinghe Chen
Thank you for your reply and sorry for my confuse text. I used wait = WebDriverWait(browser, 10), and it returns me a time exception error. I assume 10 here is 10 secs. I am wondering whether the form(select option) is not clickable.
kev
The select option is clickable, however you need do it using the right method. This is how I would click on a select option:
labels = [list of required/desirable options/a single option]; element = driver.find_element_by_id(element_id); for option in element.find_elements_by_tag_name('option'): if option.text in labels: option.click(); Do let me know if this helps. :)kev
@YingheChen Please let me know if the above code snippet is difficult to understand, I would be glad to add it as an edit to my answer.
Yinghe Chen
Thanks kev, I still have trouble clicking on the button. I think this might be caused by two things. One is that the current button is outside of browser screen, and I need to scroll down a little bit to see the button. I have tried to scroll down but still not work. Second is that this website is using ng-click, which I am not familiar with. Here is a screen shot of the code. workforothers.com/Yinghe/code.png Thank you again for your help.
(driver, 30)means that your script will wait 30 seconds for required element and raiseTimeOutExceptionif it still not clickable