简体   繁体   中英

How can I fix "Unsupported locator strategy" for XPATH which contains a valid following-sibling path?

I'm using Selenium for Python 3.x and Chrome webdriver. I would like to locate a price element using XPATH expression. HTML looks:

在此处输入图片说明

My XPATH to this element looks in this way and is valid:

//td[contains(text(), 'Montant')]/following-sibling::td/span

I can find element by this XPATH in console by

$x("//td[contains(text(), 'Montant')]/following-sibling::td/span")

ChroPath plugin and XPath helper plugin shows this XPATH as valid too. But when I run the test I get this error:

selenium.common.exceptions.WebDriverException: Message: unknown error: Unsupported locator strategy: //td[contains(text(), 'Sous total')]/following-sibling::td/span (Session info: chrome=78.0.3904.108) (Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Linux 4.15.0-70-generic x86_64)

I don't know why this XPATH generates this error and how I can fix this. Additionally, another XPATH axes don't generate the problems.

这管用吗 ?

'//td[contains(text(), 'Montant')]/../td[2]/span'

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM