I am successfully able to navigate to the desired page after logging in. Static elements are located and printed, peacefully. The page makes JavaScript call and the contents are updated after about 4-5 seconds, I'm unable to locate the dynamic elements.
I'm attaching the image of Inspect element before and after loading of Javascript elements.
Please, have a look at the code below and suggest the possible solution. P.S. Out of 100 times this worked worked for about 2-3 times.
layer = "https://desired.website"
driver.get(layer)
driver.find_element_by_id("email").send_keys('my@email.com')
driver.find_element_by_id("password").send_keys('myPassword')
driver.find_element_by_class_name("css-173kae7").click()
#NOW I'M SUCCESSFULLY LOGGED IN
#Opening the Desired Page, This is a static element
wait = WebDriverWait(driver, 30)
element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "css-1nga9gi")))
driver.execute_script('''window.open("desired.page","_blank");''')
#Successfully opened desired page and switched to newly opened tab
#Trying to access the element present in <tbody> tag, please refer "Inspect Element after JavaScript elements are loaded"- image.
wait = WebDriverWait(driver, 30)
element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "css-167dqxg")))
check = driver.find_elements_by_class_name("ccss-13ozsj7")
for e in check:
print(e.text)
print("ALL DATA SUCCESSFULLY PRINTED")
Nothing happens for 30 seconds and I get time-out error and "ALL DATA SUCCESSFULY PRINTED" is displayed.
ERROR CODE I GET IS:
element = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "css-167dqxg")))
File "C:\Python\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until
raise TimeoutException(message, screen, stacktrace)
selenium.common.exceptions.TimeoutException: Message:
Please have a look at the Inspect element.
Inspect Element at the beginning of Page Load
Inspect Element after JavaScript elements are loaded
Aucun commentaire:
Enregistrer un commentaire