我需要把所有的元素都放在一个部门里。除法根据从下拉列表中选择的值动态加载数据。因此,对于每个选定的值,在除法中有一组不同的元素。这是HTML:
<div id="container1">
<div id="container1.1">
<input id="dropdown" type="select">//dropdown for dynamically selecting elements of container1.2
<options>1</options>
<options>2</options>
</div>
<div id="container1.2">
<input type="text" id="element1">
<button id="element2">
</div>
</div>//for containerselenium代码:
List<WebElement> obj=driver.findElements(By.xpath("//[@id='Container']//*"));//to get all elements in division
System.out.println(obj.get(0).getTagName());
System.out.println(obj.get(1).getTagName());这不能给出所需的结果。我收到了以下错误:
invalid selector: Unable to locate an element with the xpath expression //[@id='Container']//* because of the following error:
SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//[@id='Container']//*' is not a valid XPath expression. 发布于 2017-04-10 10:03:37
首先,正如错误消息所述,xpath表达式无效。它应该是
List<WebElement> obj=driver.findElements(By.xpath("//div[@id='Container']//*"));或者,如果元素不特定于div,则可以使用通配符//*@id='Container‘。
在容器中列出子元素的其他方法,也许更好一些
List<WebElement> parentElements=driver.findElements(By.xpath("//div[@id='Container']"));希望这能有所帮助。
发布于 2017-04-10 10:19:50
$('.className').html();
好多了
document.getElementsByClassName('className').innerHTML
发布于 2017-04-10 11:36:21
这给出了div....use "//“中的所有元素,而不是第二次..because,它只给出根类型的元素。
List<WebElement> obj=BaseClass.driver.findElements(By.xpath("//*[@id='Container']//*"));https://stackoverflow.com/questions/43319290
复制相似问题