Find Element Text Using Xpath In Selenium-python Not Working
html looks like thisI have written this code to scrape all courses from a url. For this I am trying to get the count of courses using xpath. But it does not give me anything. Where
Solution 1:
If text
doesn't work you can try get_attribute
print total_courses.get_attribute('text')
#orprint total_courses.get_attribute('innerHTML')
Solution 2:
ele = wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, 'Not right now, thanks.')));
ele.click()
print"----------------------POP UP CLOSED---------------------"
total_courses = self.driver.find_element_by_xpath("//span[@id='number-of-courses']")
In that piece of code, I suspicious 2 things:
- Does the popup always appear?
- Does the text of
number-of-courses
show in time?
If you are not sure about 1., I would recommend to put it in a try catch
And about 2. - wait until some text appears on that element
try:
ele = wait.until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, 'Not right now, thanks.')));
ele.click()
finally:
total_courses = wait.until(EC.presence_of_element_located(By.XPATH, "//span[@id='number-of-courses' and text() != '']")
print total_courses.text
Post a Comment for "Find Element Text Using Xpath In Selenium-python Not Working"