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.我看程式碼挺工整的,感覺是可運行的程式碼。 問題應該在 self.base_url = "http://127.0.0.1/", 你本機需要開啟這個http服務。
2.selenium是python的一個操控瀏覽器的模組,選擇firefox版本不是IDE的事,是它的事,但它也沒有選擇版本這個東西,它只是調用firefox,本機裝的是什麼版本的firefox ,它用的就是什麼版本
3.先學python程式語言