gpt4 book ai didi

java - 如何在selenium中使用By.tagName查找子标记名?

转载 作者:行者123 更新时间:2023-12-01 18:01:00 27 4
gpt4 key购买 nike

我正在努力寻找子标签名称我想使用下面的代码找到“ankit patel”名字 enter image description here

我正在编写如下代码

  List<WebElement> rows= driver.findElements(By.id("ui-id-2") ); //Printing the size of the rows 
List<WebElement> lirowsx = rows.findElements(By.tagName("li"));

System.out.print(lirowsx .size() +"size ");

int s=lirowsx.size();

当我尝试使用“li”标签访问“ankit patel”时,它会返回错误消息喜欢线程“main”中的异常 org.openqa.selenium.ElementNotInteractableException:元素不可交互 ( session 信息:chrome=80.0.3987.132)我也尝试过 xpath 但没有得到结果。

您能指导我如何解决这个问题吗?

最佳答案

您可以通过先通过 xpath 找到该元素,然后获取其文本来找到该元素。
你可以这样做:

WebElement element = driver.findElement(By.xpath("//li[@class='ui-menu-item']//strong"));
// Fetching the text
String text = element.getText();

关于java - 如何在selenium中使用By.tagName查找子标记名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60629862/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com