Search code examples
pythonseleniumselenium-webdriverselenium-chromedriverwebautomation

How do I identify this numeric value using python selenium?


So for each of these rows, there is a "xxx Answers" element.

How can I extract the numeric value of it so that I can do a comparison like:

if x > 50 then blah blah.


Solution

  • Here is the xpath to get the value.

    //div[@class='u-text--gray-light-metadata']/a
    

    Python code should look something like this (you have multiple answer elements 1 per each name so you have to get elements and iterate but here I am giving sample how to get the first one)

    text =  driver.find_element_by_xpath("(//div[@class='u-text--gray-light-metadata']/a)[1]").text
    # extract the number of answers
    answers = text.split(' ')[0]