如何使用 Selenium Python 通过已知 src 属性查找元素
我试图通过使用 Selenium 和 python,通过 src 属性的已知值来查找元素。该元素是 Google 地图中某个位置的地址左侧的点图片。
即我尝试选择的元素的 html:
<img alt="" jstcache="935" src="//www.gstatic.com/images/icons/material/system_gm/1x/place_gm_blue_24dp.png" class="Liguzb" jsan="7.Liguzb,0.alt,8.src">
如何通过使用链接搜索来选择给定元素:
www.gstatic.com/images/icons/material/system_gm/1x/place_gm_blue_24dp.png
谢谢。
I am trying to find an element by using Selenium with python, by a known value of src attribute. The element is the point picture on the left of the address of a location in Google Maps.
Namely the html for the element I'm trying to select:
<img alt="" jstcache="935" src="//www.gstatic.com/images/icons/material/system_gm/1x/place_gm_blue_24dp.png" class="Liguzb" jsan="7.Liguzb,0.alt,8.src">
How can I select the given element by searching for it by using the link:
www.gstatic.com/images/icons/material/system_gm/1x/place_gm_blue_24dp.png
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
要定位元素,因为您知道
src
属性的值,您可以使用以下任一 定位器策略:使用css_selector:
使用xpath:
定位可见元素而不是presence_of_element_ located()你需要诱导WebDriverWait 的 visibility_of_element_ located( ) 并且您可以使用以下任一定位器策略:
使用CSS_SELECTOR:
使用XPATH:
注意:您必须添加以下导入:
To locate the element as the value of
src
attribute is know to you, you can use either of the following Locator Strategies:Using css_selector:
Using xpath:
To locate a visible element instead of presence_of_element_located() you need to induce WebDriverWait for the visibility_of_element_located() and you can use either of the following locator strategies:
Using CSS_SELECTOR:
Using XPATH:
Note : You have to add the following imports :