[英]Selenium Webdriver: Invalid Xpath with finding element using partial ID
I am trying to find elements using Selenium Webdriver in Python by partial class name.我正在尝试通过部分类名在 Python 中使用 Selenium Webdriver 查找元素。 I am very new to programming and tried using advice from https://intellipaat.com/community/9218/is-it-possible-to-locate-element-by-partial-id-match-in-selenium and Selenium WebDriver Finding Element by Partial Class Name
我对编程非常陌生,并尝试使用来自https://intellipaat.com/community/9218/is-it-possible-to-locate-element-by-partial-id-match-in-selenium和Selenium WebDriver 的建议按部分类名称的元素
My code is as follows:我的代码如下:
list5=driver.find_elements_by_xpath("//[contains(@id,‘partial id’)]")
Please let me know what is wrong with this code, as it says it is not a valid XPath expression.请让我知道这段代码有什么问题,因为它说它不是有效的 XPath 表达式。 Thank you!
谢谢!
You are using ´
instead of '
, try like this:您正在使用
´
而不是'
,请尝试这样:
list5=driver.find_elements_by_xpath("//[contains(@id,'partial id')]")
And since I don't know what exactly are you looking for, you might need to add tag name ( div
, span
, etc.) after //
ie //div
or of course //*
if you want any element.因为我不知道你到底在找什么,你可能需要在
//
ie //div
之后添加标签名称( div
、 span
等),当然如果你想要任何元素, //*
。
For example if you do it for the page we are currently on you could write:例如,如果您为我们当前所在的页面执行此操作,则可以编写:
//div[contains(@id,'question')]
and you would get 3 div
elements which have ids: question-header
, question
and hot-network-questions
你会得到 3 个具有 id 的
div
元素: question-header
、 question
和hot-network-questions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.