Skip to content Skip to sidebar Skip to footer

How To Pull Out Text From A Div Class Using Selenium Headless

I'm trying to pull out the '0%' from the following div tag:
0%
my current code is: from selenium import webdriver from se

Solution 1:

As per the HTML you have shared to extract the text 0% you need to use the method get_attribute("innerHTML") and you can use either of the following solutions:

  • css_selector:

    myText = driver.find_element_by_css_selector("div.sem-report-header-td-diff").get_attribute("innerHTML")
    
  • xpath:

    myText = driver.find_element_by_xpath("div[@class='sem-report-header-td-diff']").get_attribute("innerHTML")
    

Solution 2:

First of all, not "elements", it is "element". and, second point is, you didn't get ttext. you just called element.

so, here is the code:

element_text = driver.find_element_by_xpath("//div[@class='sem-report-header-td-diff']").text

Post a Comment for "How To Pull Out Text From A Div Class Using Selenium Headless"