Trying to have selenium click a button on a webpage. Cannot find the element to make it click.
<button type="submit" class="xButton xCTA xSubmit">
<span>Enter</span>
</button>
Trying to have selenium click a button on a webpage. Cannot find the element to make it click.
<button type="submit" class="xButton xCTA xSubmit">
<span>Enter</span>
</button>
driver.find_element_by_xpath("//button[@class='xButton xCTA xSubmit'].click()
driver.find_element_by_css_selector("button[type='submit']").click()
driver.find_element_by_xpath("//span[contains(text(), 'Enter')]").click()
Any of those should do the trick.
Though the <button>
have no or
attribute you can still use the other attributes, e.g. class
, innerText
, etc.
To click()
on the element with text as Enter you need to induce WebDriverWait for the element to be clickable() and you can use either of the following Locator Strategies:
Using Python and CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.xButton.xCTA.xSubmit[type='submit'] > span"))).click()
Using Java and XPATH
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='xButton xCTA xSubmit']/span[text()='Enter']"))).click();