0

The Webpage

<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. I'm not sure why xpath doesn't work but do you know how to implement find by text for the strong?

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.

Does anyone know how to find the strong element using find by link text, im not sure how to implement that

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

1

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()

2 Comments

So I stupidly realised maybe it was due to having multiple tabs open. But even after closing the irrelevant tabs it turns out it wasn't it. Maybe this changes something though?
Moment! Initially you was on first browser window and then you clicked some button etc. and a second browser window is opened, visually you see that the focus is now switched to the second window and the element we trying to click is located there, on the second window?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.