【问题标题】:Way to find the elements from the html code从 html 代码中查找元素的方法
【发布时间】:2017-04-21 11:54:51
【问题描述】:

我在需要自动化的网站上有这些详细信息:

物业详情

Zip:10001
Neighborhood:Midtown
City:New York City
State:NY

这是城市的 html 详细信息,例如:

<div class="row propertyDetailsRow margin-bottom-10px ng-scope" ng-if="property.City != null">
   <strong style="margin-right: 10px;">City:</strong>
   <span class="ng-binding">New York City</span>
</div>
<strong style="margin-right: 10px;">City:</strong>
<span class="ng-binding">New York City</span>

有什么方法可以找到元素 City 和元素 New York City 以便在我的代码中使用它们? 我需要找到 lhs 元素和写在它们旁边的值。 例如 City,值为 New York City。 有没有办法从这个 html 中获取元素的详细信息?

谢谢

【问题讨论】:

  • 你试过 findElementByXpath 吗?
  • 你已经尝试了什么?
  • 请阅读How to AskHow much research effort is expected?请提供您尝试过的代码和执行结果,包括任何错误信息等。同时提供页面链接和/或相关HTML。

标签: java selenium selenium-webdriver


【解决方案1】:

尝试使用 XPATH。安装一个像 FirePath 这样的工具来帮助自己调试这个,然后可能试试这个:

"//div[contains(text(), 'City:')]//span"

或者试试这个

//div[contains(@class,'row propertyDetailsRow margin-bottom-10px ng-scope')]//span[@class='ng-binding']

【讨论】:

  • 我尝试使用 findElementByXpath 但无论我使用什么属性,我总是收到以下错误:SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//div[contains(text( ),'City:']//span' 不是有效的 XPath 表达式
猜你喜欢
  • 1970-01-01
  • 2018-04-29
  • 1970-01-01
  • 2017-05-23
  • 1970-01-01
  • 2020-03-23
  • 2013-01-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多