Python Selenium find_element_by_xpath can't find elements

84 views
Skip to first unread message

Steve C

unread,
Nov 8, 2020, 12:37:53 PM11/8/20
to Selenium Users

New to Python and Selenium. Trying to get list of elements that match a xpath or css_selector and extract link text. Searched and tried many variations but everything I've tried returns an empty list. Apparently not using the correct xpath or css_selector values.

Have tried all of these...

elements = driver.find_elements_by_css_selector('a[href="viewoffender.do"]') elements = driver.find_elements_by_css_selector("[href='%viewoffender.do']") elements = driver.find_elements_by_xpath('//a[contains(@href, "viewoffender.do")]') elements = driver.find_elements_by_xpath("/html/body/div/div[6]/div/table[2]/tbody/tr[3]/td[1]/a") elements = driver.find_elements_by_css_selector(".tableRowEven > td:nth-child(1) > a:nth-child(1)") elements = driver.find_elements_by_xpath("//*[starts-with(@id, 'link-viewoffender.do')]") 

HTML page can be found here...https://drive.google.com/file/d/1m-cM90JHNqVLhlOZFHZIOOenLWRkkisX/view?usp=sharing

Steve C

unread,
Nov 10, 2020, 6:11:35 AM11/10/20
to Selenium Users
It appears I needed to wait. Added this just before looking for the elements and all the suggestions worked. I ended up using this code instead and no problems... 
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located( (By.CLASS_NAME, "tableRowHeader")))
Reply all
Reply to author
Forward
0 new messages