1

I visited: http://132.247.137.206/web/guest/en/websys/webArch/mainFrame.cgi

and wrote the following in python (after waiting for page to load)

try:
    tmp = driver.find_elements(By.XPATH, '//*[text()="Login"]')
    print(tmp)
except Exception as e:
    print('NONE FOUND!')

But all I see being printed is:

[]

Why is that?

I'm expecting the above code to return ay item in the page link or button that has the word Login.

Roi
  • 49
  • 6

1 Answers1

1

[] denotes empty list as the locator strategy you have used doesn't identifies the element within the DOM Tree.


Deep Dive

The element with text as Login is within an <frame>:

login


Solution

To identify the element you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.

  • Induce WebDriverWait for the desired element to be clickable.

  • You can use either of the following Locator Strategies:

    • Using XPATH:

      driver.get("http://132.247.137.206/web/guest/en/websys/webArch/mainFrame.cgi")
      WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//frame[@title='Header Area']")))
      print(WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Login']"))))
      
  • Note : You have to add the following imports :

     from selenium.webdriver.support.ui import WebDriverWait
     from selenium.webdriver.common.by import By
     from selenium.webdriver.support import expected_conditions as EC
    
  • Console Output:

    <selenium.webdriver.remote.webelement.WebElement (session="224f5eafafd1c7422d408810378cd6ec", element="d4e316c3-3187-42e9-b1d2-054cbab92f0b")>
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Thank you, what can be done for general case? Ie. looking for any button or link with the text login? I don't know what the frame name will be either – Roi Apr 11 '22 at 19:31
  • Sounds to be a different question all together. Feel free to raise a new question as per your new requirement. – undetected Selenium Apr 11 '22 at 19:32
  • Plus question, why do I need to switch to the frame first? why can't selenium just find it as if it was outside frame – Roi Apr 11 '22 at 19:37