自动化测试 - selenium IDE导出到Python文件,提示错误: 不支持命令selectFrame
黄舟
黄舟 2017-04-18 10:09:21
0
1
1061

test case:

tk
open /new_post
selectFrame index=0
click link=评论
sendKeys class=autosize Auto Test
keyDown class=autosize 13
keyUp class=autosize 13

导出的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 Test(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.implicitly_wait(30)
        self.base_url = "http://127.0.0.1/"
        self.verificationErrors = []
        self.accept_next_alert = True
    
    def test_(self):
        driver = self.driver
        driver.get(self.base_url + "/new_post")
        # ERROR: Caught exception [ERROR: Unsupported command [selectFrame | index=0 | ]]
        driver.find_element_by_link_text(u"评论").click()
        # ERROR: Caught exception [Error: unknown strategy [class] for locator [class=autosize]]
        # ERROR: Caught exception [ERROR: Unsupported command [keyDown | class=autosize | \13]]
        # ERROR: Caught exception [ERROR: Unsupported command [keyUp | class=autosize | \13]]
    
    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException as e: return False
        return True
    
    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException as e: return False
        return True
    
    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True
    
    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

我该怎么修改Python代码才能让其正常运行呢?以及若要使用selenium IDE该如何选择firefox版本?从哪里入手学习呢?谢谢大家

黄舟
黄舟

人生最曼妙的风景,竟是内心的淡定与从容!

모든 응답(1)
伊谢尔伦

1. 코드가 상당히 깔끔하고 실행 가능한 코드라는 느낌이 듭니다. 문제는 self.base_url = "http://127.0.0.1/"이어야 합니다. 로컬 시스템에서 이 http 서비스를 활성화해야 합니다.

2. Selenium은 브라우저를 제어하는 ​​Python 모듈입니다. Firefox 버전을 선택하는 것은 IDE의 업무가 아니라, 설치된 버전을 확인하기 위해 Firefox를 호출하는 것뿐입니다. Firefox, 어떤 버전을 사용하고 있나요

3. 먼저 Python 프로그래밍 언어를 배워보세요

최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!