Title: Selenium TimeoutException when locating email field on LinkedIn sign-up page
Description:
My automated test fails when trying to locate the email field on LinkedIn's sign-up page after clicking "Join now". The test throws a TimeoutException
after 5 seconds of waiting, despite the element being visible when I manually inspect the page.
Error Details: File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\unittest\case.py", line 628, in run testMethod() File "C:\Users\User\PycharmProjects\LinkedinApp\TestLinkedin.py", line 28, in test_SignUp email_element = WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_xpath(email)) File "C:\Users\User\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:
Relevant Code:
email = ".//*[@id='join-email']" # Current XPath selector
email_element = WebDriverWait(driver, 5).until(
lambda driver: driver.find_element_by_xpath(email))
What I've Tried:
Verified the element exists in DevTools (ID: join-email)
Increased wait time to 10+ seconds
Confirmed the page loads completely
Tried both XPath and CSS selector approaches
Additional Information:
Using Selenium 3.141.0 with Python 3.7
ChromeDriver version: [your version here]
The element HTML (from DevTools):
<input id="join-email" name="email" type="text">
There is nothing wrong with your locator strategy, i think you wrong placement WebDriverWait
for email locator .//*[@id='join-email']
, this locator appears after you click Join now
. You can try this code :
join_now_element = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_link_text(join_now))
join_now_element.click()
#first_name_element = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_name(first_name))
#last_name_element = WebDriverWait(driver, 10).until(lambda driver: driver.find_element_by_name(last_name))
email_element = WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_xpath(email))
#password_element = WebDriverWait(driver, 5).until(lambda driver: driver.find_element_by_id(password))
#agree_and_join_element = WebDriverWait(driver, 5).until( lambda driver: driver.find_element_by_name(agree_and_join))
And it looks like you don't need to wait for first_name_element
last_name_element
password_element
agree_and_join_element
, it's already represented by email_element