2016-09-21 9 views
0

おはよう。私がPython 2.7に行ったテストをエクスポートして、Pythonと一緒にFirefox上でSelenium IDEを使用する方法を学んでいます。iframeで動作するPython Selenium webdriver

私のテストでは、いくつかの問題が発生しました。その1つは、iframeの内側にある2つのテキストフィールドを認識していないということです。 Iveはスタックオーバーフローに関して他のいくつかの答えを見つけましたが、私のコードにそれらを適用する方法は本当にわかりません。これは、私がfirefoxでSelenium IDEから直接エクスポートしたものです。私はPythonとプログラミング全般に全く新しいので、どんな提案も歓迎されるでしょう。

これは私が今持っているものです。

# -*- coding: utf-8 -*- 
from selenium import webdriver 
from selenium.webdriver.common.by import By 
from selenium.webdriver.common.keys import Keys 
from selenium.webdriver.support.ui import Select 
from selenium.common.exceptions import NoSuchElementException 
from selenium.common.exceptions import NoAlertPresentException 
import unittest, time, re 

class StiMPythonWebdriver(unittest.TestCase): 
    def setUp(self): 
     self.driver = webdriver.Firefox() 
     self.driver.implicitly_wait(30) 
     self.base_url = "https://webpage.com/" 
     self.verificationErrors = [] 
     self.accept_next_alert = True 

    def test_sti_m_python_webdriver(self): 
     driver = self.driver 
     driver.find_element_by_id("SEARCHS").clear() 
     driver.find_element_by_id("SEARCHS").send_keys("403627") **It inserts a code of a form** 
     driver.find_element_by_id("splitbutton1-button").click() 
     # ERROR: Caught exception [ERROR: Unsupported command [waitForPopUp | details403627 | 100000]] 
     # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=details403627 | ]] **It waits a little for the pop up window to open so it can continue the test** 
     driver.find_element_by_id("editButton_textSpan").click() 
     Select(driver.find_element_by_id("status")).select_by_visible_text("Option 1") 
     # ERROR: Caught exception [ERROR: Unsupported command [selectFrame | id=descrpt_ifr | ]] 
     # ERROR: Caught exception [ERROR: Unsupported command [selectFrame | id=tinymce | ]] **Right here at this part it is supposed to select the <p> inside the Iframe and type the following sentence "Canceled"** 


     driver.find_element_by_id("descrpt_ifr").clear() 
     driver.find_element_by_id("descrpt_ifr").send_keys("Canceled") 
     # ERROR: Caught exception [ERROR: Unsupported command [selectWindow | name=details403627 | ]] 
     driver.find_element_by_id("goButton_textSpan").click()**then it selects a button that exits the pop up** 
+0

あなたの質問は私には分かりません。あなたは実際に何を達成したいですか?関連性の高いHTMLを共有して詳細を教えてください。 –

答えて

1

あなたがウィンドウに切り替えたい場合はiframe

driver.switch_to_frame(driver.find_element_by_xpath("//iframe[@id='tinymce ']")) 

に切り替えたい場合は-1デフォルトアクティブウィンドウに

driver.switch_to_window(driver.window_handles[-1]) 
です

完了したら元に戻すのを忘れることはありません。

関連する問題