0

Update: here's a screenshot of the frame I'm having trouble switching to: frame that cannot be located

I've tried selecting this element multiple different ways but always get the "unable to locate" error.

I can easily locate elements on most pages but I suspect this html requires an extra step or two to get at the link.

Here's the html--the link is in the 3rd line:

<div class="menu_bg">
    <ul class="menu">
        <li id="retrieve"><a href="https://s1.ebridge.com/ebridge/3.0/retrieve/search.aspx?search=new&amp;guid=4ae139ed-287a-4087-8fe0-56ff3683e160" id="aView" onclick="clickme(this,'retrieve')" target="main">Retrieve</a></li>
        <li id="help"><a id="aSupport" onclick="clickme(this,'reports')" target="main" href="Support/support_main.aspx?guid=4ae139ed-287a-4087-8fe0-56ff3683e160">Support</a></li>
        <li style="float: right;">
            <span id="cabnm" class="cabinet_box">PinCHD</span>
        </li>
    </ul>
</div>

This element is on a page behind a login page here which I have no problem logging into using the following code:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from bs4 import BeautifulSoup
import re
import pandas as pd
import os
from selenium.webdriver.common.by import By
url = "https://s1.ebridge.com/ebridge/3.0/default.aspx?1"
driver = webdriver.Firefox(executable_path="/Applications/Postgres.app/Contents/Versions/11/bin/geckodriver")
driver.implicitly_wait(30)
driver.get(url)
username = driver.find_element_by_name("tbUserName")
username.clear()
username.send_keys("public")
password = driver.find_element_by_name("tbPassword")
password.clear()
password.send_keys("public")
file_cabinet = driver.find_element_by_name("tbFileCabinet")
file_cabinet.clear()
file_cabinet.send_keys("PINCHD")
file_cabinet.send_keys(Keys.RETURN)

After this runs, the page that contains the link I'm having trouble locating loads. I've tried finding by id, xpath, css selector, link text, and partial link text without success.

I'm hoping someone can look at the html at the top of my question and tell me how they'd go about locating the link in the third line so that I can then issue a click() on it.

screenshot of page behind login with element circled and arrow pointing to html

Latest Update w/error:

>>> from selenium import webdriver
>>> from selenium.webdriver.common.keys import Keys
>>> from bs4 import BeautifulSoup
>>> import re
>>> import pandas as pd
>>> import os
>>> from selenium.webdriver.common.by import By
>>> url = "https://s1.ebridge.com/ebridge/3.0/default.aspx?1"
>>> driver = webdriver.Firefox(executable_path="/Applications/Postgres.app/Contents/Versions/11/bin/geckodriver")
>>> driver.implicitly_wait(30)
>>> driver.get(url)
>>> username = driver.find_element_by_name("tbUserName")
>>> username.clear()
>>> username.send_keys("public")
>>> password = driver.find_element_by_name("tbPassword")
>>> password.clear()
>>> password.send_keys("public")
>>> file_cabinet = driver.find_element_by_name("tbFileCabinet")
>>> file_cabinet.clear()
>>> file_cabinet.send_keys("PINCHD")
>>> file_cabinet.send_keys(Keys.RETURN)
>>> driver.implicitly_wait(15)
>>> driver.switch_to.frame("header")

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/switch_to.py", line 89, in frame
    self._driver.execute(Command.SWITCH_TO_FRAME, {'id': frame_reference})
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchFrameException: Message: Unable to locate frame: b91c4c93-d8fd-e543-9ce2-a58ade0081db

>>> retrieve = driver.find_element_by_xpath("//*[@id="aView"]")
  File "<stdin>", line 1
    retrieve = driver.find_element_by_xpath("//*[@id="aView"]")
                                                          ^
SyntaxError: invalid syntax
>>> retrieve.click()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'retrieve' is not defined

2 Answers 2

1

The element you are looking for is inside a frame, so first you need to switch to that frame and then search for the element like this.

driver.switch_to.frame('header')  #Match by name of the frame
my_element = driver.find_element_by_xpath('//*[@id="aView"]')
my_element.click()
Sign up to request clarification or add additional context in comments.

7 Comments

Thanks but what is the name of the frame? So far I've tried "aView", "body", "retrieve" and "Retrieve" without success.
I also tried "header" but that didn't work either. It may be worth noting that the alphanumeric string at the end of the URL of the link I'm after changes every time you login.
The screenshot which you shared, shows that name field of frame element is "header", so you can use that to switch to the frame. BTW, where are you getting the issue? Did you click on the element after searching for it? I have updated the answer with code to click on element.
I'm updating my question with the full code + the error message.The error occurs right after >>> driver.switch_to.frame("header"). The message is "selenium.common.exceptions.NoSuchFrameException: Message: Unable to locate frame: 8409b24a-966a-0e44-b901-37da679e5db1".
I am not sure why that is not working for you, can you try these two other options for switching frame. 1. driver.switch_to.frame(0) 2. driver.switch_to.frame((By.NAME, 'header'))
|
0

Answering my own question here:

The problem was with the Firefox (geckodriver) webdriver. I encountered no issues when using the Chrome driver.

Comments

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.