'Not able to print the text without using time.sleep() in Selenium Python
Not able to get the Text with the below code from the print statement in Python Selenium but when i am trying to add time.sleep(4) before print(new_cases.text) statement then i am able to get the text.I am using Explicit wait.Can anyone help me what is the issue here?
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get("https://covid-19-dc.herokuapp.com/");
wait = WebDriverWait(driver,120)
wait.until(EC.visibility_of((driver.find_element(By.XPATH, "//p[@id='new_case']"))))
new_cases = driver.find_element(By.XPATH, "//p[@id='new_case']")
print(new_cases.text)
driver.quit()
Solution 1:[1]
You don't need to use find_element in visibility_of, use visibility_of_element_located instead. find_element is executed internally, so the returned value is the WebElement you waited for
new_cases = wait.until(EC.visibility_of_element_located((By.XPATH, "//p[@id='new_case']"))
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Guy |
