单击带有 selenium 和 python 的 href 按钮?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19601086/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 14:08:57  来源:igfitidea点击:

Click a href button with selenium and python?

pythonseleniumbuttonclickhref

提问by Findios

I have one button from one LinkedIn page with this code:

我在一个 LinkedIn 页面上有一个带有以下代码的按钮:

<div class="primary-action-button"><a class="primary-action label" href="/requestList?displayProposal=&amp;destID=39959446&amp;creationType=DC&amp;authToken=Yr4_&amp;authType=OUT_OF_NETWORK&amp;trk=vsrp_people_res_pri_act&amp;trkInfo=VSRPsearchId%3A2998448551382744275729%2CVSRPtargetId%3A39959446%2CVSRPcmpt%3Aprimary">Send InMail</a></div>

Is there any way to click on an element just by its href link? Thanks

有没有办法仅通过其 href 链接单击元素?谢谢

采纳答案by Ben Smith

Using selenium you could use the following code:

使用硒,您可以使用以下代码:

driver.find_element_by_link_text("Send InMail").click()

回答by Anna

The above answer driver.findElement(By.linkText("Send InMail")).click();is in Java. In python, use find_element_by_link_text:

上面的答案driver.findElement(By.linkText("Send InMail")).click();是在Java中。在python中,使用find_element_by_link_text

driver.find_element_by_link_text('Send InMail').click()

or something like this is sometimes helpful

或类似的东西有时会有所帮助

driver.find_element_by_partial_link_text('Send').click()