1

I am having problem locating a single report element embedded in iframe. There many reports contains in table where iframe is located. Also using the firefox firePath it is given me a very link and am not sure how to remove the long strings. Edited the code:

    browser.switch_to_frame(browser.find_element_by_tag_name("iframe"))
    # set the context on the child frame
    browser.switch_to_frame(browser.find_element_by_id("__gwt_historyFrame"))

    # set the context on the next child frame
   wait = WebDriverWait(self.browser, 10)
        browser.switch_to_frame(wait.until(EC.presence_of_element_located(By.ID,"com.demandreports.wb.Workbench")))

    #click the link
    wait.until(EC.presence_of_element_located(By.LINK_TEXT,"Invoice Aging Report")).click()

    # switch back to the main document context
    browser.switch_to_default_content()

This is error:

    Traceback (most recent call last):
  File "C:\Python34\zuoraDataexport6.py", line 118, in <module>
    scraper.scrape()
  File "C:\Python34\zuoraDataexport6.py", line 57, in scrape
    browser.switch_to_frame(browser.find_element_by_id("com.demandreports.wb.Workbench"))
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 234, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 712, in find_element
    {'using': by, 'value': value})['value']
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
    self.error_handler.check_response(response)
  File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"id","selector":"com.demandreports.wb.Workbench"}

This is what i want to locate: Invoice Aging Report

This is the html:

<document>
    <html style="overflow: hidden;">
    <head>
    <body style="margin: 0px;">
    <iframe id="__gwt_historyFrame" style="position:absolute;width:0;height:0;border:0" tabindex="-1" src="javascript:''"/>
    <iframe id="com.demandreports.wb.Workbench" src="javascript:''" style="position: absolute; width: 0px; height: 0px; border: medium none;" tabindex="-1"/>
    <table class="Workbench-Page" cellspacing="0" cellpadding="0">
    <tbody>
    <tr>
    <tr>
    <tr>
    </tbody>
    </table>
    </body>
    </html>
</document>
2
  • have you tried this ? stackoverflow.com/questions/18924146/… Commented Mar 24, 2016 at 6:03
  • It didn't work got a timeout exception. I have edited code. Commented Mar 24, 2016 at 6:39

1 Answer 1

1

The context is not set on the frame where your element is. You need to switch to each frame on the tree line:

# set the context on the child frame
browser.switch_to_frame(browser.find_element_by_id("__gwt_historyFrame"))

# set the context on the next child frame
browser.switch_to_frame(browser.find_element_by_id("com.demandreports.wb.Workbench"))

#click the link
wait.until(EC.presence_of_element_located(By.LINK_TEXT,"Invoice Aging Report")).click()

# switch back to the main document context
browser.switch_to_default_content()
Sign up to request clarification or add additional context in comments.

8 Comments

Hi Florent, i did what you have told me and have a new exceptions. please see above.
I've updated the answer, it now waits for the link to be present.
Hi Florent, i have updated your code and have received another errror.please see above.
Do you at least understand what this error and the previous one mean?
limited in iframe. when html page load it ignore iframe. i have tried this but an error has ocurred. 'browser.switch_to_frame(wait.until(EC.presence_of_element_located(By.ID,"com.demandreports.wb.Workbench")))' TypeError: __init__() takes 2 positional arguments but 3 were given'
|

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.