Can't switch frames - keep getting AttributeError

my first post. We apologize in advance for any mistakes.

I am writing in Python using Selenium trying to clear some information from some web pages.

I cannot solve this puzzle after two days of searching and searching.

My problem is this; when trying to login to w / Selenium / Python site, I cannot "find item" to login. After searching for a long time, I realize that I may need to switch frames to find an element. I tried the command switchTo

(or switch_to) in different ways - and I keep getting the message

"Attribute Error: SwitchTo instance does not have a method call ."

I'll post the most recent attempt (let me know if I can provide any further information):

In selenium:

waitUntilReady(browser)  
browser.switch_to().frame(browser.findElement(By.ID("iframe[id='credentials']")))
elem = WebDriverWait(browser, 60).until(EC.presence_of_element_located((By.NAME, "Ecom_User_ID")))
elem = browser.find_element_by_name("Ecom_User_ID")
elem.send_keys("frustrated")

      

What is returned (in terminal):

File "someproj.py", line 56, in browser.switch_to (). frame (browser.findElement (By.ID ("['credentials' ID =] IFrame"))) AttributeError: SwitchTo instance has no call method

html site of the form:

 <!DOCTYPE html>

    <html lang="en" webdriver="true">
        <head></head>
        <body onload="onloadhandler()">
            <div class="m-header"></div>
            <div class="container">
                <div class="header"></div>
                <div class="ten columns">
                    <h2></h2>
                    <iframe id="loginsubtab" height="375" frameborder="0" width="100%" src="/nidp/jsp/content.jsp?sid=0&id=289&sid=0" scrolling="no">
                        #document
                            <!DOCTYPE html>
                            <html lang="en" webdriver="true">
                                <head></head>
                                <body onload="onloadhandler('selectedCard')">
                                    <div id="content">
                                        <table border="0" width="100%">
                                            <tbody>
                                                <tr>
                                                    <td>
                                                        <iframe id="credentials" height="375" frameborder="0" width="100%" src="/nidp/saml2/sso?id=289&sid=0&option=credential&sid=0" scrolling="no">
                                                            #document

      

Thanks a lot for any ideas or recommendations !!!

+3


source to share


2 answers


You are using the wrong selector. The selector you are using is cssSelector, but NOT id



waitUntilReady(browser)  
# or use id as follows
# browser.switch_to.frame(browser.findElement(By.ID, 'credentials'))
#browser.switch_to.frame(browser.find_element_by_id('credentials'))
browser.switch_to.frame(browser.findElement(By.CSS_SELECTOR, "iframe[id='credentials']"))
elem = WebDriverWait(browser, 60).until(EC.presence_of_element_located((By.NAME, "Ecom_User_ID")))
elem = browser.find_element_by_name("Ecom_User_ID")
elem.send_keys("frustrated")

      

+1


source


First, it doesn't look right:

browser.findElement(By.ID("iframe[id='credentials']"))

      

Since you are looking for an element by ID, you don't need to include iframe[id="..."]



try:

browser.findElement(By.ID('credentials'))

      

0


source







All Articles