【问题标题】:Can some please suggest me ,how to write xpath for images.Please find below xpath is valid or not有人可以建议我,如何为图像编写 xpath。请在下面找到 xpath 是否有效
【发布时间】:2019-02-13 13:37:59
【问题描述】:

我尝试了以下定位器但没有用:

//div[@id="SidebarContent"]//a[@href='/catalog/categories/BIRDS']

请帮我找到正确的定位器...

网址:This is the URL

下面是用户名和密码:-

username:Testing
Password:test@123

【问题讨论】:

  • StackOverflow 不是用于检查您的代码是否正确...您可以在浏览器中执行此操作...

标签: selenium


【解决方案1】:

你想要图片或链接吗?

图片(如果需要链接,请删除 /img):

xpath="//div[@id='SidebarContent']/a[contains(@href,'FISH')]/img"
xpath="//div[@id='SidebarContent']/a[contains(@href,'DOGS')]/img"
xpath="//div[@id='SidebarContent']/a[contains(@href,'REPTILES')]/img"
xpath="//div[@id='SidebarContent']/a[contains(@href,'CATS')]/img"
xpath="//div[@id='SidebarContent']/a[contains(@href,'BIRDS')]/img"

我更喜欢使用不那么脆弱的 css 选择器:

css="div#Sidebar div#SidebarContent a[href*='FISH'] img"
css="div#Sidebar div#SidebarContent a[href*='DOGS'] img"
css="div#Sidebar div#SidebarContent a[href*='REPTILES'] img"
css="div#Sidebar div#SidebarContent a[href*='CATS'] img"
css="div#Sidebar div#SidebarContent a[href*='BIRDS'] img"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-07-06
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-30
    • 1970-01-01
    • 2017-02-08
    相关资源
    最近更新 更多