单击带有 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
Click a href button with selenium and python?
提问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=&destID=39959446&creationType=DC&authToken=Yr4_&authType=OUT_OF_NETWORK&trk=vsrp_people_res_pri_act&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()