[英]Cannot accessing link using selenium python via xpath or link text
<div class="span3"> <div class="stat-panel"> <div class="stat-cell1 bg-stats1 valign-middle" style="text-align: center;"> <a href="co-op/coopjobs.htm"><strong>View and Apply for<br> Co-op Jobs</strong></a> </div> </div> </div>
This is a broader view of the code of that box, The clickable part seems to be the a tag and the strong tag.这是该框代码的更广泛视图,可点击部分似乎是a标签和strong标签。 I'm not sure why xpath doesn't work but do you know how to implement find by text for the strong?
我不确定为什么 xpath 不起作用,但你知道如何为强者实现文本查找吗?
I'm not sure how to access the link above.我不确定如何访问上面的链接。 I want to click on a link that is written using the code above with selenium webdriver python.
我想单击使用上面的代码和 selenium webdriver python 编写的链接。
Does anyone know how to find the strong element using find by link text, im not sure how to implement that有谁知道如何使用通过链接文本查找来查找强元素,我不确定如何实现
XPATH: XPATH:
//a[contains(@href, "co-op/coopjobs.htm")]
and click on it like this:然后像这样点击它:
driver.find_element_by_xpath("//a[contains(@href, "co-op/coopjobs.htm")]").click()
for clicking on anchor tag, remember always linkText
or partialLinkText
is preferred.要单击锚标记,请记住始终首选
linkText
或partialLinkText
。
This should work:这应该有效:
driver.find_element_by_xpath("//a[contains(@href,'co-op/coopjobs.htm')]").click()
If this doesn't work for you we need more information.如果这对您不起作用,我们需要更多信息。
So, the above locator is not a unique.所以,上面的定位器不是唯一的。
You need to use the following:您需要使用以下内容:
driver.find_element_by_xpath("//a[contains(@href,'co-op/coopjobs.htm') and(contains(text(),'View and Apply for'))]").click()
Try this:尝试这个:
from selenium.webdriver.common.action_chains import ActionChains
element = driver.find_element_by_xpath("//a[contains(@href,'co-op/coopjobs.htm') and(contains(text(),'View and Apply for'))]")
actions = ActionChains(driver)
actions.move_to_element(element).perform()
element.click()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.