2016-03-24 68 views
0

iframeに埋め込まれた単一のレポート要素の検索に問題があります。 iframeがあるテーブルには多くのレポートが含まれています。また、firefox firePathを使用すると、それは私に非常にリンクが与えられ、長い文字列を削除する方法がわかりません。編集されたコード:Python Selenium用のiframeに埋め込まれた要素の検索方法

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() 

これはエラーです:

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"} 

これは私が見つけたいものです:レポート

エージング 請求書は、これは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> 
+0

これを試しましたか? http://stackoverflow.com/questions/18924146/selenium-and-iframe-in-html – HaseebR7

+0

タイムアウト例外が発生しました。私はコードを編集しました。 –

答えて

0

コンテキストは、要素があるフレームに設定されません。ツリー線の各フレームに切り替える必要があります。

# 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() 
+0

こんにちはFlorent、私はあなたが私に言ったことをして、新しい例外があります。上記をご覧ください。 –

+0

答えを更新しました。リンクが存在するのを待っています。 –

+0

こんにちはFlorent、私はあなたのコードを更新し、上記の別のerrror.pleaseを受け取りました。 –

関連する問題