- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
HTML
<div class="top-section" style="" xpath="1">
<input id="role" value="admin" hidden="">
<small>Welcome </small> <b style="">8828024404, MCGM</b>
<a href=""><img alt="Attendance" width="" height="" src="css/assets/images/logo.png"></img></a>
<a href="/logout" class="float-right logout">Log Out</a>
</input>
</div>
要搜索的字符串
8828024404, MCGM
Xpath 表达式
//b[matches(text(),'[0-9]{10}, [A-Za-z]*')]
异常
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //b[matches(text(),'[0-9]{10}, [A-Za-z]')] because of the following error: SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//b[matches(text(),'[0-9]{10}, [A-Za-z]')]' is not a valid XPath expression. (Session info: chrome=70.0.3538.102) (Driver info: chromedriver=2.42.591088 (7b2b2dca23cca0862f674758c9a3933e685c27d5),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds
最佳答案
Selenium 支持 XPath 1.0 版本,而 fn:matches
来自 XPath 2.0。
如果您想匹配以逗号前 10 位数字开头的粗体文本,您可以尝试下面的 XPath
//b[string-length(substring-before(., ','))=10 and number(substring-before(., ','))]
如果您对所需元素有更多限制,请告诉我
关于selenium - Xpath 使用匹配项和正则表达式在 Xpath 测试器中工作,但在代码中抛出 InvalidSelectorException 无法在 'evaluate' 上执行 'Document',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53354813/
我正在使用 Appium 自动化 android 应用程序。我正在尝试使用 Android SDK 提供的 UIAutomatorviewer 工具定位元素。以下是我找到的 xpath,但我认为它可能
我对使用 Selenium 非常陌生。我试图单击以下选择按钮: 这是我的代码: import org.openqa.selenium.By; import org.openqa.selenium.We
动机 利用 Selenium 的 CSS 选择器机制以及 CSS 属性选择器和 HTML5 data- 自定义属性来解决元素的特定 Hook 。 问题 当使用上面的方法来定位分配有 CSS 类名和 d
我正在尝试使用 XPATH 从以下内容中检索值 email1、Email2 和 HT email1 Email2 HT 以下是我的 XPATH 代码: int
将 Weblogic 版本从 10.3.6 升级到 12.1.2 后,我得到 javax.jms.InvalidSelectorException 调用 JMS API 时 javax.jms.Que
我正在尝试使用 CssSelector 在我的网页上定位一个元素。我正在使用 Firefox 驱动程序。 这是我使用定位器的方式(我检查过 Selenium IDE 能够用它定位我的元素 [Finds
当我试图从文本框中获取值时,它抛出 No such element found issues, 以下是我的字段属性: input id="altid" class="firstColumnInput
我正在 firefox 中开发 selenium python。我正在尝试通过 css 选择器查找元素 element = "span:contains('Control panel')" my_dr
我正在 firefox 中开发 selenium python。我正在尝试通过 css 选择器查找元素 element = "span:contains('Control panel')" my_dr
我正在尝试编写一个脚本来处理具有多个元素的网页。单击此元素将打开一个新窗口。但是我的脚本在识别元素时有问题。我需要帮助来定位元素和处理多个窗口 我尝试使用 Chrome 查找 Xpath,但它在 In
我正在学习 Selenium Webdriver 并尝试编写一个简单的测试脚本。 目的是获取About Google Gmail 页面上的链接以练习 CSS 定位器。 代码如下: public cla
HTML Welcome 8828024404, MCGM Log Out 要搜索
org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the
我以前从未遇到过这样的错误。我正在访问的网站是否无法使用自动化测试? 代码: public class DirectoryAutomation { public static void mai
我正在尝试单击以下 HTML 中的最后一个 span 元素 ... 在Java中使用Selenium,代码如下: driver.fin
我在尝试使用 Selenium 上传文件时遇到问题。由于浏览按钮没有输入标签,我无法使用 sendKeys() 函数传递路径。它是用 Angular 编写的。 这是浏览按钮元素: 我确实在源代码中的
我是一名优秀的程序员,十分优秀!