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>
Ricard Le
  • 55
  • 1
  • 2
  • 12

1 Answers1

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()
Florent B.
  • 41,537
  • 7
  • 86
  • 101
  • Hi Florent, i did what you have told me and have a new exceptions. please see above. – Ricard Le Mar 24 '16 at 22:04
  • I've updated the answer, it now waits for the link to be present. – Florent B. Mar 24 '16 at 22:22
  • Hi Florent, i have updated your code and have received another errror.please see above. – Ricard Le Mar 24 '16 at 22:39
  • Do you at least understand what this error and the previous one mean? – Florent B. Mar 24 '16 at 22:53
  • 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' – Ricard Le Mar 24 '16 at 23:11
  • You should check in the DOM that the frame are the correct ones. – Florent B. Mar 24 '16 at 23:21
  • Is it possible if we could take this offline. i could send you a the screen shot of the DOM. – Ricard Le Mar 24 '16 at 23:37
  • hi florent i don't have 20 reputations to have a discussion. i have shortened the above html. the report i want to grab is in tr[3].this is xpath html/body/table/tbody/tr[3] – Ricard Le Mar 25 '16 at 00:26