Selenium Webdriver Can't Find Element Sometimes
I'm trying to find the search box on tripadvisor but sometimes it is not able to find it. (I get timeout error). I have added WebDriverWait and time.sleep but to no avail. I am sti
Solution 1:
To find the search box on Tripadvisor instead of presence_of_element_located()
you have to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following Locator Strategies:
Using
CSS_SELECTOR
:searchbox = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[name='q'][title='Search']")))
Using
XPATH
:searchbox = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@name='q' and @title='Search']")))
Note: You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
Solution 2:
To entered value in search input
box
Use WebDriverWait
() and wait for element_to_be_clickable
() and following xpath.
searchbox = WebDriverWait(driver,20).until(EC.element_to_be_clickable((By.XPATH, "//input[@aria-label='Search']")))
Post a Comment for "Selenium Webdriver Can't Find Element Sometimes"