Selenium and Python to find elements and text?

后端 未结 2 902
臣服心动
臣服心动 2020-12-28 18:34

When I go to a certain webpage I am trying to find a certain element and piece of text:



        
相关标签:
2条回答
  • 2020-12-28 18:50

    The problem is actually with the class name as the spaces causes the element to have 3 different classes (separated by the space)

    If you set the class to Bold-Orange-Large instead it should work as expected with the elem.text method.

    0 讨论(0)
  • 2020-12-28 18:52

    you want: elem.text to get "the number that is inside".

    explanation:

    in your example, elem is an instance of webdriver's WebElement class (from selenium.webdriver.remote.webelement)

    a WebElement instance has several properties, including:

    • tag_name
    • text
    • size
    • location
    • parent
    • id

    .text property contains "the content"


    "and my other problem is that there are multiple of those exact span elements ..how can I deal with that?"

    please don't ask several questions in one.. it doesn't work well with SO's format.

    but basically, use the find_elements_* instead of find_element_*. your locator can then return a list of matching WebElement instances instead of a single matching instance... which you can filter further.

    0 讨论(0)
提交回复
热议问题