首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用Selenium和Java在没有值标记时如何提取值

使用Selenium和Java在没有值标记时如何提取值
EN

Stack Overflow用户
提问于 2022-02-11 20:37:08
回答 1查看 137关注 0票数 0

我想得到输入标签的值,并与两个数字之和进行比较。但是没有值标签,或者我看不到结果号。我试着得到,但我得到了零。图片和输入标签如下所示。

代码语言:javascript
复制
<input _ngcontent-lbg-c92="" matinput="" type="number" class="mat-input-element mat-form-field-autofill-control ng-tns-c35-2 cdk-text-field-autofill-monitored ng-untouched ng-pristine" style="text-align: center;" id="mat-input-2" aria-invalid="false" aria-required="false" disabled="">

元素快照:

EN

回答 1

Stack Overflow用户

发布于 2022-02-11 21:15:39

要打印值(即1626 ),可以使用以下任何一个

使用

  • 的cssSelector:

System.out.println(driver.findElement(By.cssSelector("input.mat-input-elementid^='mat-input'matinput")).getAttribute("value"));

使用xpath的

System.out.println(driver.findElement(By.xpath("//inputcontains(@class,‘mat-’)并以(@id,'mat-input')")).getAttribute("value")); )开头

但是,由于该元素是一个动态元素,因此要标识需要为WebDriverWait导入presenceOfElementLocated()的元素,您可以使用以下任何一个

使用

  • 的cssSelector:

新20).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("inputid*='Empty'"))).getAttribute("value")); (驱动程序,System.out.println)

使用xpath的

20).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//input@value='emptyAssembly‘System.out.println(新的WebDriverWait(驱动程序,System.out.println),包含(@id,'Empty')"))).getAttribute("value")); )

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71086272

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档