2016-09-21 3 views
0

Guten Tag. Ich versuche zu lernen, wie man die Selenium IDE auf Firefox zusammen mit Python verwendet, indem ich jeden Test, den ich mit Python 2.7 gemacht habe, exportiert habe.Python Selenium webdriver arbeiten mit iframes

Während meines Tests stieß ich auf ein paar Probleme, eines davon ist, dass es 2 Textfelder nicht erkennt, die in Iframes sind. Ich habe einige andere Antworten hier auf Stack-Überlauf gefunden, aber ich bin nicht wirklich sicher, wie man sie auf meinen Code anwendet. Dies ist, was ich vom Export direkt von der Selenium IDE auf Firefox erhalten habe. Ich bin auch völlig neu bei Python und Programmierung im Allgemeinen, daher wäre jeder Vorschlag auch willkommen.

Das ist, was ich jetzt haben:

# -*- 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

Ihre Frage ist mir nicht klar. Was willst du eigentlich erreichen ?? Könntest du auch relevantes HTML teilen und mehr ausarbeiten? –

Antwort

1

Wenn Sie

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

iframe wechseln möchten Wenn Sie Fenster wechseln möchten -1 scheint aktive Fenster Standard

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

Vergessen Sie nicht, zurück zu schalten, wenn Sie fertig sind.

Verwandte Themen