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

2 Answers2

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()
ThePyGuy
  • 1,025
  • 1
  • 6
  • 15
SeleniumUser
  • 4,065
  • 2
  • 7
  • 30
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).

Agate
  • 3,152
  • 1
  • 19
  • 30
  • i got the following message: selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//a/span[text() = 'Home']/.."} – Kyocera Alerts Mar 20 '20 at 20:43
  • 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. – Agate Mar 20 '20 at 20:58