【问题标题】:How to click on a link with an anchor tag on a page through selenium webdriver and java如何通过selenium webdriver和java点击页面上带有锚标签的链接
【发布时间】:2018-10-25 02:07:51
【问题描述】:
<a href="https://www.pharmacistexcellence.com/index/aboutpep#pepLinkSection">
    <img class="iconBulletLink" style="vertical-align:middle; position: relative; top: -1px;" src="https://www.pharmacistexcellence.com/assets/images/icon-bullet.png" width="25">        
</a>

<div style="vertical-align:middle; display:inline;" class="anchr sixthAnch beforeAnch afterAnch">
About PEP
</div>

我可以使用什么类型的定位器?

【问题讨论】:

  • 没有任何细节我们应该如何回答?请分享与您的问题相关的实际代码(如果需要)和有关您的问题的详细信息,请更具体。另外,请阅读How Do I ask Good Questions

标签: html selenium selenium-webdriver xpath css-selectors


【解决方案1】:

根据您共享的HTML,您可以使用以下任一定位器策略Java 透视图):

  • cssSelector

    driver.findElement(By.cssSelector("a[href='https://www.pharmacistexcellence.com/index/aboutpep#pepLinkSection']>img.iconBulletLink")).click();
    
  • xpath

    driver.findElement(By.xpath("//a[@href='https://www.pharmacistexcellence.com/index/aboutpep#pepLinkSection']/img[@class='iconBulletLink']")).click();
    

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-05-23
    • 2013-01-10
    • 2012-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多