Issue
I'm trying to locate a "log in" button on a webpage and then to click it using the "LINK_TEXT" method, however it seems selenium is unable to locate this button for some reason: Code:
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
try:
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Log In"))).click()
except:
print('exception occured')
driver.quit()
time.sleep(3)
driver.close()
When I inspect element for the button in Chrome I can see the following:
<button class="btn btn-block btn-red ng-binding" id="login-button" ng-click="onLoginClick($event)">Log In</button>
So I can see the link text is showing as "Log In" for this particular page so the LINK_TEXT method should've detected this but isn't.
Any ideas?
Thanks in adavance
Solution
To click on Log In
button use any of the below locator strategy
.
XPath:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Log In']"))).click()
CSS selector:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button#login-button"))).click()
ID:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "login-button"))).click()
Answered By - KunduK
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.