html - 通过 cssSelector 查找元素
问题描述
我对 Selenium 很陌生,我正在征求您的建议。
我有以下html:
<div class="order">
<a style="float: left;" href="#137674" class="voidCmn ui-button ui-corner-all ui-widget" role="button">Void</a>
<a style="float: left;" href="printcmn.php?Id=137674" target="_blank" class="ui-button ui-corner-all ui-widget" role="button"> Print </a>
<a style="float: left;" href="section_a.php?cmnId=137674&origin=viewreferral.php" class="ui-button ui-corner-all ui-widget" role="button"> Edit </a>
</div>
在那种情况下,我想使用 cssSelector 而不是 xpath。
我查找网页元素按钮编辑的代码(见上文):
Driver.findElement(By.cssSelector("a.ui-button.ui-corner-all.ui-widget[role='button'][href^='viewreferral.php']"));
但是,我收到一个错误:
no such element: Unable to locate element: {"method":"css selector","selector":"a.ui-button.ui-corner-all.ui-widget[role='button'][href^='viewreferral.php']"}
您能否回顾一下并告诉我出了什么问题。
解决方案
请使用下面给定的 css 选择器,它应该可以工作:
a.ui-button.ui-corner-all.ui-widget[role='button'][href*='viewreferral.php']
您使用了错误的运算符来检查包含。你用过:^
但它应该是*
推荐阅读
- cassandra - 非素数属性的 IN 运算符
- c# - 如何在 Web API 中管理 POST 请求
- java - Avro - java.io.IOException:不是数据文件
- python - 为什么 ColumnTransformer 不调用 fit 它的变压器?
- javascript - 如何在 React JS 中应用动画
- twitter - Social Studio Radian6 获取推文数据
- python - 无法在烧瓶中使用 monogdb 运行 docker-compose
- java - 无法从数据库中检索数据(Firebase)
- ibm-mq - 我能否在仍使用 WAS 8.5.5 的同时将我的 MQ 版本升级到 9.0?
- r - 无法对下载按钮进行条件检查