1

This is my first time using Python and Selenium. The first part of the code works but when it goes to the second page it can never find any of the elements. If I flip the code and make it go to the second site first, it works. What am I doing wrong here? I tried xpath, CSS_Selector, Class_Name seems like nothing is working. This is the error I get:

Traceback (most recent call last): File "C:\Users\dresd\PycharmProjects\Test2\main.py", line 20, in click_Register = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.CLASS_NAME, "q-text qu-ellipsis qu-whiteSpace--nowrap"))).click() File "C:\Users\dresd\AppData\Local\Programs\Python\Python310\lib\site-packages\selenium\webdriver\support\wait.py", line 89, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
import time

driver = webdriver.Chrome ("C:/chromedriver.exe")

driver.get("https://10minutesemail.net/")

Copy_Email = WebDriverWait(driver, 20).until(
    EC.presence_of_element_located((By.ID, "copyEmailAddress"))).click()

time.sleep(10)

driver.execute_script("window.open('https://quora.com/','_blank')")

click_Register = WebDriverWait(driver, 20).until(
    EC.presence_of_element_located((By.CLASS_NAME, "q-text qu-ellipsis qu-whiteSpace--nowrap"))).click()

name = driver.find_element(By.NAME, "profile-name")
email = driver.find_element(By.ID, "email")

name.send_keys("Jackson Fuller")

Thanks in advance!

1
  • What element are you trying to click on quora page? Commented Feb 22, 2022 at 14:15

1 Answer 1

0

You have to switch the driver to the new opened tab.
Without that the focus will remain on the first browser window.
TimeoutException actually means that Selenium could not locate element by passed locator.
Also the locator you are using is bad.
Try this:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
import time

driver = webdriver.Chrome ("C:/chromedriver.exe")

driver.get("https://10minutesemail.net/")

Copy_Email = WebDriverWait(driver, 20).until(
    EC.presence_of_element_located((By.ID, "copyEmailAddress"))).click()

time.sleep(10)

driver.execute_script("window.open('https://quora.com/','_blank')")

driver.switch_to.window(driver.window_handles[1])
click_Register = WebDriverWait(driver, 20).until(
    EC.presence_of_element_located((By.CLASS_NAME, "q-text qu-ellipsis qu-whiteSpace--nowrap"))).click()

name = driver.find_element(By.NAME, "profile-name")
email = driver.find_element(By.ID, "email")

name.send_keys("Jackson Fuller")
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you :) But I still need to fix the locator here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.