需要帮助来阅读div元素中的文本

时间:2016-09-19 08:53:56

标签: selenium-webdriver

PFB代码段

<div id='divId'>
<span></span>
here is the text
<span></span>
</div>

driver.findElement(By.id("divId")).getText()无效。请建议我在java代码中阅读本文的方法

3 个答案:

答案 0 :(得分:0)

该文字显示在span而不是div中。因此,您应该使用包含span的xpath。喜欢这里 -
https://sqa.stackexchange.com/questions/22590/how-to-find-int-value-within-span-class-selenium-c/22604#22604

答案 1 :(得分:0)

试试这个xpath

// div [@ id ='这里是文字']

如果它工作那么好。否则,打开selenium IDE然后单击“查找”按钮将鼠标拖动到要查找的特定元素,然后单击该元素。现在,您可以在目标字段中找到不同的定位器值。

希望它能运作

答案 2 :(得分:0)

尝试:

driver.findElement(By.id("divId")).getAttribute("innerHTML");

driver.findElement(By.id("divId")).getAttribute("outerHTML");

如果它没有返回特定文本,你可以从那里解析它