Using Python 2, Selenium using Firefox, on this page, I am trying have the driver click the following button (the magnifying glass):
<button id="search-btn" type="button" class="header__user-menu-item header__search-btn">
<span class="sr-only">Search</span>
<img src="/sites/default/themes/custom/smp_bootstrap/images/search.svg" class="header__user-menu-icon fa fa-search fa-fw" alt="Search">
</button>
I use the following code for the XPath of the element, x = '//*[@id="search-btn"]'
:
x = '//*[@id="search-btn"]'
try:
element = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, x)))
except:
print "Element not clickable"
else:
found_element = driver.find_element_by_xpath(x)
try:
found_element.click()
except:
raise
Selenium's common exception EC.element_to_be_clickable
doesn't identify the element, nor does visibility_of_element_located
nor presence_of_element_located
.
Strangely however, at a few occasions the driver has actually been able to identify the element and then perform driver.find_element_by_xpath(x)
which appears to find the XPath and .click()
the element. At that point everything works. For a second I thought that the script was to quick to execute the operation before the page had loaded, but 5 seconds WebDriverWait
is plenty to load the page, and I have an additional page-load-in sleep before that.
The element doesn't seem to be in an IFrame. I have already passed through the "Accept Conditions"-buttons, etc.
I am running the latest versions of Firefox (61.0), Selenium (3.13) and Geckodriver (0.21.0).
What could be the problem here?