我正在使用 selenium,并且我已经在 redhat linux 6 上正确安装了 selenium 模块。下面是我的脚本:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.common.exceptions import NoSuchElementException
import unittest, time, re
import zlib
class Sele1(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.implicitly_wait(30)
self.base_url = "https://bugzilla.example.com/"
self.verificationErrors = []
def test_sele1(self):
driver = self.driver
driver.get(self.base_url + "/")
driver.find_element_by_id("Bugzilla_login").clear()
driver.find_element_by_id("Bugzilla_login").send_keys("username")
driver.find_element_by_id("Bugzilla_password").clear()
driver.find_element_by_id("Bugzilla_password").send_keys("password")
driver.find_element_by_id("log_in").click()
driver.find_element_by_id("quicksearch").clear()
driver.find_element_by_id("quicksearch").send_keys("new bugs is bugzilla tool")
driver.find_element_by_xpath("//input[@value='Find Bugs']").click()
def is_element_present(self, how, what):
try: self.driver.find_element(by=how, value=what)
except NoSuchElementException, e: return False
return True
def tearDown(self):
self.driver.quit()
self.assertEqual([], self.verificationErrors)
if __name__ == "__main__":
unittest.main()
当我运行此脚本时,它显示错误:
错误:test_sele1(主要.Sele1)
Traceback(最近一次调用最后一次):文件“sele1.py”,第 19 行,在 test_sele1 driver.find_element_by_id("Bugzilla_login").clear() AttributeError: 'NoneType' object has no attribute 'clear'
在 2.018 秒内运行 1 次测试
失败(错误=1)
平台:Redhat Python 版本:2.6
注意:在 windows7 中运行相同的脚本时,它运行良好,但在 python2.6 的 linux 中没有运行
请帮助我...提前致谢!