调试的时候好好的,运行的时候就不行了
这是源码:# 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
import unittest,time,re
import HTMLTestRunner
class Baidu(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(40)
self.base_url = "http://www.baidu.com/"
self.verificationErrors = []
self.accept_next_alert = True
#百度搜索用例
def test_baidu_search(self):
driver = self.driver
driver.get(self.base_url + '/')
driver.find_element_by_id("kw").send_keys("selenium")
driver.find_element_by_id("su").click()
time.sleep(2)
driver.close()
#白度设置用例
def test_baidu_set(self):
driver = self.driver
driver.get(self.base_url + '/gaoji/preferences.html')
m = driver.find_element_by_name("NR")
m.click()
#time.sleep(2)
t = m.find_element_by_xpath("/html/body/form/table/tbody/tr/td/select/option")
#time.sleep(2)
t.click()
#time.sleep(2)
driver.find_element_by_id("save").click()
#time.sleep(2)
driver.switch_to_alert().accept()
def tearDown(self):
self.driver.quit()
self.assertEqual([],self.verificationErrors)
if __name__ == "__main__":
testunit = unittest.TestSuite()
#testunit.addTest(Baidu("test_baidu_search"))
testunit.addTest(Baidu("test_baidu_set"))
filename = "result.html"
fp = file(filename,'wb')
runner = HTMLTestRunner.HTMLTestRunner(
stream=fp,
title = u"百度搜索测试报告",
description = u'用例执行情况:'
)
runner.run(testunit)
请大神们帮忙看看:$ xpath用绝对路径不稳定,最好换成相对路径 prettyfool 发表于 2016-2-29 19:32
xpath用绝对路径不稳定,最好换成相对路径
谢谢啦
页:
[1]