0

I'm having issues clicking an A HREF on a website. Please see below for an inspection on the A HREF and the steps that I've tried. Any assistance is greatly appreciated.

enter image description here

I've tried:

 browser.switch_to.default_content()
 frames = browser.find_elements_by_tag_name('frame')
 browser.switch_to.frame(frames[1])
 browser.find_element_by_xpath("//a[contains(@href,'Home')]").click()

and also:

 browser.find_element_by_xpath('//a[@href="javascript:openWorkFrame(\'/web/entry/en/websys/webArch/topPage.cgi\');"]').click()
3
  • can you please share your site Commented Mar 20, 2020 at 21:06
  • it's a private site. Are you looking for anything specific? Commented Mar 20, 2020 at 21:37
  • Does this answer your question? Select iframe using Python + Selenium Commented Mar 20, 2020 at 22:12

2 Answers 2

2

Try to switch to your first frame using browser.switch_to_frame(element) and then use below xpath to click on a link

frame = browser.find_element_by_name('header')
browser.switch_to_frame(frame)
browser.find_element_by_xpath("//a/span").click()
browser.switch_to_default_content()
Sign up to request clarification or add additional context in comments.

Comments

0

Maybe you could try this XPath expression?

xpath_expr = "//a/span[text() = 'Home']/.."
browser.find_element_by_xpath(xpath_expr).click()

Basically, find the span element with text = "Home", then select its parent (the link).

2 Comments

i got the following message: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a/span[text() = 'Home']/.."}
Sorry then, I'm not familiar enough with Selenium, maybe the frame is getting in the way? I'd recommend creating a simplifiede test case by copying the basic structure of your DOM, and share it here so people can experiment with XPath expressions.

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.