how do I get around this error 'webelement does not support indexing"[webdriver][python]

后端 未结 2 481
不思量自难忘°
不思量自难忘° 2021-01-15 01:19

I am doing an xpath search

page = driver.find_element_by_xpath(\'//td[@class=\"mceIframeContainer mceFirst mceLast\"]\')[1]

This gives me t

相关标签:
2条回答
  • 2021-01-15 01:27

    Like most of the Selenium WebDriver bindings, if you only specify "element", you will only return the first found element. However, if you specify "elements" in your method, it will return an array of elements found.

    So your code should be:

    page = driver.find_elements_by_xpath('//td[@class="mceIframeContainer mceFirst mceLast"]')[1]
    

    See http://selenium.googlecode.com/svn/trunk/docs/api/py/webdriver_remote/selenium.webdriver.remote.webdriver.html?highlight=find_element_by_xpath#selenium.webdriver.remote.webdriver.WebDriver.find_elements_by_xpath

    0 讨论(0)
  • 2021-01-15 01:48

    the [1] needs to be added in part of the string

    for example for a bunch of identical forms on a webpage, the first xpath might be

    /html/body/form/table/tbody/tr[1]/td[2]/input

    and the second would be

    /html/body/form/table/tbody/tr[2]/td[2]/input

    OR you might be able to use find_elements_by_xpath instead, and then they could be indexable thats find_element***s***_by_xpath with an S

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