如何抓取文本对应的复选框在硒的webdriver? [英] How to grab text corresponding to checkboxes in selenium webdriver?
问题描述
我使用selenium webdriver来运行脚本。
I am using selenium webdriver to run script.
我有一个场景,我想抓取对应于复选框的文本。
I have a scenario where I want to grab text corresponding to checkboxes.
对于单个复选框,我使用getAttribute()来捕获下面代码中给出的文本,并且工作正常。
For a single checkbox I am using getAttribute() to capture text as given in below code and it is working fine.
String referenceIn3DPage=Driver.driver.findElement(By.xpath("//div[3][@class='some-class']//input")).getAttribute("id");
findElements()的情况下getAttribute无效吗?
Does getAttribute invalid in case of findElements() ?
如何为多个复选框捕获文本?
How to capture text for multiple checkbox?
复选框的屏幕截图:
Screenshot of checkbox:
HTML萤幕撷取画面:
HTML screenshot:
正如你在截图中看到的,我想要属性 - id来捕获我的文本。
As you can see in screenshot I want the attribute - id to capture my text.
推荐答案
从您另一个问题中获取代码并修改它。
Just taking the code from you another question and modifying it.
String referenceIn3DPage =null;
int count=Driver.driver.findElements(By.xpath("//div[3][@class='viewer3d-demo-commercial-references-checkboxes']//input")).size();
System.out.println("the count="+count);
for(int i=1;i<=count;i++)
{
referenceIn3DPage=Driver.driver.findElement(By.xpath("//div[3][@class='viewer3d-demo-commercial-references-checkboxes']/div["+i+"]/label/input")).getAttribute("id");
System.out.println("the value in 3d= "+referenceIn3DPage);
}
请运行上面的代码,让我知道如果它给出了预期的结果
Kindly run the above code and let me know if it gives you the expected result.
这篇关于如何抓取文本对应的复选框在硒的webdriver?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!