selenium教程:利用谷歌浏览器获取xpath的定位信息

2022-10-1821:31:12编程语言入门到精通Comments1,083 views字数 351阅读模式

使用selenium各种定位的时候,是不是经常遇到定位难的问题,现在推荐大家使用谷歌浏览器的神器,帮我们获取想要的定位元素,今天主要介绍xpath,其它方式类似!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

打开谷歌浏览器开发者模式文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

selenium教程:利用谷歌浏览器获取xpath的定位信息文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

选择元素这栏,然后光标定位到我们想要获取的内容处文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

selenium教程:利用谷歌浏览器获取xpath的定位信息文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

然后谷歌会自动定位到我们所点数据的元素位置文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

接下来就是见证奇迹的时刻了文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

右击鼠标-Copy - Copy Xpath文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

selenium教程:利用谷歌浏览器获取xpath的定位信息文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

然后粘贴复制的信息:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

//*[@id="grid-count-area"]/li[1]/span

完美,将改内容粘贴到我们的代码中:文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

mapStr = driver.find_element_by_xpath("//*[@id='grid-count-area']/li[1]/span").text
print("mapStr:",mapStr)
selenium教程:利用谷歌浏览器获取xpath的定位信息文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

完美的获取到数据!文章源自菜鸟学院-https://www.cainiaoxueyuan.com/ymba/28442.html

  • 本站内容整理自互联网,仅提供信息存储空间服务,以方便学习之用。如对文章、图片、字体等版权有疑问,请在下方留言,管理员看到后,将第一时间进行处理。
  • 转载请务必保留本文链接:https://www.cainiaoxueyuan.com/ymba/28442.html

Comment

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定