【问题标题】:How do I click on the href link?如何点击href链接?
【发布时间】:2021-06-20 19:08:42
【问题描述】:

我已经尝试使用 driver.find_element_by_id // link_text // 部分链接文本,我应该使用什么来访问这个 href。我得到了没有这样的元素例外。任何帮助将不胜感激 tysm。

    
<a href="../s-reminderNotice.asp?fname=b%2D3c%2DpLessonBooking%2Easp%3Flimit%3Dpl" 
class="sidelinkbold" target="mainFrame" onmouseover=" 
window.status='Practical Training Booking'; return true" onmouseout="window.status=' '; 
return true">Booking without Fixed Instructor</a>


已解决;元素在一个框架中;必须切换框架以访问元素

【问题讨论】:

  • 你遇到了什么异常?
  • 无此类元素异常;我将其编辑到帖子中

标签: python html selenium href


【解决方案1】:

尝试使用:

webDriver.findElement(By.xpath("//a[@href='YOUR LINK']")).click();

【讨论】:

  • 我试过这个但没有用;没有ID就不能访问链接吗?
【解决方案2】:
driver.find_element_by_class_name("sidelinkbold").click()

它有一个简单的类名,您可以使用它来点击。

【讨论】:

  • 这不起作用,因为网站左侧有一整列属于同一类
  • 那么下面的答案作为 xpath 就可以了。
【解决方案3】:

试试下面的 WebElement 然后点击它:

//a[contains(text(),'Booking without Fixed Instructor')]

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-08-31
    • 2019-05-06
    • 2014-01-22
    • 1970-01-01
    • 1970-01-01
    • 2020-07-14
    • 2012-10-06
    • 1970-01-01
    相关资源
    最近更新 更多