I'm trying to load a URL which has dynamic HTML. The selenium webdriver loads the URL fine, but it appears to be searching for elements before the HTML has fully rendered. I tried WebDriverWait, but that does not appear to work.
Interestingly, after selenium fails to find the element, I can manually use the Chrome developer tools to find the element successfully.
Any ideas?
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
chromepath = "C:\\Program Files (x86)\\Google\\Chrome\\Application\\chromedriver.exe"
url = "https://www.msci.com/end-of-day-data-search"
delay = 15 #seconds
br = webdriver.Chrome(chromepath)
br.get(url)
try:
br.find_element_by_class_name("accept-btn").click()
print("accepted terms and conditions")
finally:
try:
labelxpath = "//*[@id='form-content']/table[1]/tbody/tr[2]/td/span"
labelElement = WebDriverWait(br, delay).until(lambda br: br.find_element_by_xpath(labelxpath))
print(labelElement)
except:
print("could not find label")
br.close()
Script results: "accepted terms and conditions" "could not find label"