当前位置: 首页 > 知识库问答 >
问题:

如何单击id值在不同场景中变化的文本字段“数量”

侯博易
2023-03-14
 <div id="div_12_1_1_1_3_1_2_1_1_1_2" class="Quantity CoachView CoachView_show" data-eventid="" data-viewid="qty" data-config="config12" data-bindingtype="Decimal" data-binding="local.priceBreak.quantity" data-type="com.ibm.bpm.coach.Snapshot_a30ea40f_cb24_4729_a02e_25dc8e12dcab.Quantity">
<div class="w-decimal w-group clearfix">
<div class="p-label-container span4">
<div class="p-fields-container controls-row span8 l-input fixed-units">
<input id="div_12_1_1_1_3_1_2_1_1_1_2-in" class="p-field span8" type="text" maxlength="16">
 <input id="div_12_1_1_1_3_1_2_1_1_1_2-iu" class="p-unit span4" type="text" maxlength="2" style="display: none;">
<select class="p-unit span4" style="display: none;"></select>
<div class="p-unit span4">CM</div>
<div class="p-help-block"></div>
</div>
<div class="p-fields-container span8 l-output" style="display: none;">
</div>
</div>
<div id="div_12_1_1_1_3_1_2_1_1_1_3" class="Quantity CoachView CoachView_show"         data-eventid="" data-viewid="Quantity2" data-config="config73" data-bindingtype="Integer" data-binding="local.priceBreak.numberDeliveries" data-type="com.ibm.bpm.coach.Snapshot_a30ea40f_cb24_4729_a02e_25dc8e12dcab.Quantity">

此处,如何单击id为“div\u 12\u 1\u 1\u 3\u 1\u 2\u 1\u 1\u 2-in”的文本框,但在某些情况下,它会更改为“div\u 5\u 1\u 1\u 3\u 1\u 2\u 1\u 1\u 2-in”

我尝试了以下方法,

driver.findElement(By.xpath("//div/input[ends-with(@id,'__1_1_1_3_1_2_1_1_1_2-in')]")).sendKeys("98989998989");

但它不起作用。。

输出:

组织。openqa。硒。InvalidSelectorException:给定的选择器//div/input[以(@id,'\u 1\u 1\u 3\u 1\u 2\u 1\u 1\u 2-in')结尾]无效或未生成WebElement。出现以下错误:InvalidSelectorError:由于以下错误,无法找到xpath表达式//div/input[以(@id,'\uu 1\u 1\u 3\u 1\u 2\u 1\u 1\u 1\u 2-in')结尾]的元素:[异常…”表达式不是合法表达式代码:“51”nsresult:“0x805b0033(NS\u ERROR\u DOM\u INVALID\u EXPRESSION\u ERR)”位置:file:///C:/Users/SUNIL~1.WAL/AppData/Local/Temp/anonymous4157273428687139624webdriver-profile/extensions/fxdriver@googlecode.com/组件/driver\u组件。js行:5956“]命令持续时间或超时:41毫秒有关此错误的文档,请访问:http://seleniumhq.org/exceptions/invalid_selector_exception.html内部版本信息:版本:“2.37.0”,版本:“a7c61cb”,时间:“2013-10-18 17:15:02”

共有3个答案

秦学林
2023-03-14

以结尾的是一个XPath 2查询,其中五个主要查询都不支持v2

您可以选择使用已经建议的其他方法,也可以使用XPath 1解决方案:

//div/input[substring(@id, string-length(@id) - 22) = '_1_1_1_3_1_2_1_1_1_2-in']

虽然真的很难看。

松秦斩
2023-03-14

如果始终存在“in”文本,则可以使用xpath。您可以尝试//div[包含(@id,'in')]

空鸿云
2023-03-14

您可以尝试使用以下CSS选择器,

driver.findElement(By.cssSelector("div.fixed-units > input[id$='in']")).sendKeys("98989998989");
 类似资料:
  • 在这里,如何单击id为“div_12_1_1_1_3_1_2_1_1_1_2-IN”的文本框,但在某些情况下,该文本框更改为“div_5_1_1_1_3_1_2_1_1_1_2-IN” 我尝试了以下几种方法, 但它不起作用。 输出: invalidselectorexception:给定的选择器//div/input[ends-with(@id,'__1_1_1_3_1_2_1_1_1_1_2-i

  • 我正在做java fx,我陷入了将变量传递到不同的FXML场景中。因此在第一个场景控制器上,LoginController与login.fxml相关联 当新场景打开时,我需要根据包含用户输入的username变量设置标签。这意味着我们需要通过controoler将变量从login.fxml传递到mainscreen.fxml。我如何实现这一点?

  • 我有一个PDF中定义的表单。表单中的一个字段是多行文本字段。 文本字段中的值由使用Apache PDFBox的java程序填充。 问题是当值大约为5到6行时,文本框会自动显示文本。但如果超过6行,则文本框不显示该值。我必须特别点击文本字段来显示文本。如果我再次单击文本框外,文本将消失。

  • 我无法从多个文本字段中获取文本。我正在使用带有场景生成器的NetBeans作为UI扩展。每次运行程序时,都会出现以下错误: 线程“JavaFX Application thread”java.lang.RuntimeException中的异常:java.lang.reflect.InvocationTargetException 我已初始化我的文本字段如下:EmailController.java

  • 如何在单击按钮后聚焦文本字段。我尝试使用自动对焦,但没有成功:示例沙盒