[英]How to get click on 'href' link using selenium
how do i click on the href link: href="/in/xy-07976b159/" using selenium?如何使用 selenium 单击 href 链接:href="/in/xy-07976b159/"?
<a data-control-id="SOR2sXWgS8mDhCUEgFncpQ==" data-control-name="search_srp_result" href="/in/x-y-
07976b159/" id="ember1502" class="search-result__result-link ember-view"> <h3 id="ember1503"
class="actor-name-with-distance search-result__title single-line-truncate ember-view"> <span
class="name-and-icon"><span class="name-and-distance">
<span class="name actor-name">x y</span>
<span data-test-distance-badge="" id="ember1504" class="distance-badge separator ember-view">
<span class="visually-hidden">
1st degree connection
</span>
<span class="dist-value">1st</span>
</span>
</span><!----></span>
</h3>
</a>
You can click it with the help of below command.您可以在以下命令的帮助下单击它。
driver.find_elements_by_xpath("//a[@id='ember1502']").click();
Where driver is the web driver instance.其中 driver 是 web 驱动程序实例。
You can do it both ways.你可以用两种方式来做。
1) Find this element (eg. by id) and invoke method.click() on it. 1) 找到这个元素(例如,通过 id)并在其上调用 method.click()。
2) Go to page (using driver.get(youcurrenturl + yourextracted href)) 2) Go 到页面(使用 driver.get(youcurrenturl + yourextracted href))
Another way of doing using find_element_by_id
method.另一种使用find_element_by_id
方法的方法。
driver = webdriver.Chrome()
driver.get('http://www.YourUrl.com')
driver.find_element_by_id('ember1502').click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.