【问题标题】:Unable to locate link using selenium web driver无法使用 selenium Web 驱动程序找到链接
【发布时间】:2023-04-04 15:54:01
【问题描述】:

你能帮我在下面的代码中找到一个链接Taschen吗?

代码:

<a data-flyout-target="handbags" title="Taschen" href="#">Taschen</a>

【问题讨论】:

    标签: selenium-webdriver href


    【解决方案1】:

    您可以通过多种方式识别此链接:-

    1. 通过.Xpath
    2. 作者.LinkText

    Xpath:-

    //a[text()='Taschen']
    //a[@data-flyout-target = 'handbags']
    //a[@title='Taschen']
    

    因此您可以使用driver 对象来识别它,例如:-

    driver.findElement(By.xpath("Put any of the above xpaths"));
    

    或使用链接文本

    driver.findElement(By.linkText("Taschen"));
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-11
      • 2019-01-14
      • 2017-11-06
      • 2020-09-30
      • 2015-09-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多