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://test.robotscloud.com/"
self.verificationErrors = []
self.accept_next_alert = True
def test_(self):
driver = self.driver
driver.get(self.base_url + "/adminsystem/platform_user")
driver.find_element_by_id("email").clear()
driver.find_element_by_id("email").send_keys("2@163.com")
driver.find_element_by_id("password").clear()
driver.find_element_by_id("password").send_keys("123456")
driver.find_element_by_id("submit").click()
driver.find_element_by_link_text(u"系统管理").click()
driver.find_element_by_link_text(u"平台子用户设置").click()
driver.find_element_by_link_text(u"新增").click()
driver.find_element_by_css_selector("div.form-group.button-group > button.btn.btn-blue").click()
driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys("2@163.com")
driver.find_element_by_css_selector("div.form-group.button-group > button.btn.btn-blue").click()
driver.find_element_by_name("email").click()
driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys("@163.com")
driver.find_element_by_css_selector("div.form-group.button-group > button.btn.btn-blue").click()
driver.find_element_by_name("email").click()
driver.find_element_by_name("email").clear()
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()
运行后报driver.find_element_by_link_text(u"平台子用户设置").click()这个错误 但这个我在wind10python2.7上面运行正常 在wind7python2.7.12上面运行就报错,怎么解决
报什么错误附上来看看咯~~ 若尘_51 发表于 2016-12-1 16:51
报什么错误附上来看看咯~~
======================================================================
ERROR: test_ (__main__.test)
----------------------------------------------------------------------
Traceback (most recent call last):
File "F:\萝卜头自动化脚本\管理平台\xitongguanl.py", line 26, in test_
driver.find_element_by_link_text(u"绯荤粺绠$悊").click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 317, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 752, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 192, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: \u7cfb\u7edf\u7ba1\u7406
----------------------------------------------------------------------
Ran 1 test in 38.389s
FAILED (errors=1)
调用谷歌跑程序这里没有错,狐火就会报错 15889369825 发表于 2016-12-1 17:03
======================================================================
ERROR: test_ (__main__.t ...
加个等待时间或者换种定位方法试试~~ 若尘_51 发表于 2016-12-1 17:08
加个等待时间或者换种定位方法试试~~
加了时间等待,但没效果,定位方式也换了,还是不行,不知道是不是定位错误 15889369825 发表于 2016-12-1 17:10
加了时间等待,但没效果,定位方式也换了,还是不行,不知道是不是定位错误
这就怪了,没辙了,没遇过这种情形。 若尘_51 发表于 2016-12-1 17:19
这就怪了,没辙了,没遇过这种情形。
换成调用谷歌就ok了,是不是脚本的可读性太差 15889369825 发表于 2016-12-1 17:27
换成调用谷歌就ok了,是不是脚本的可读性太差
没遇到过这种情况,也不好判断是什么原因:
在谷歌里执行没有问题,起码说明脚本没有问题。
有可能是:
(1)编码的问题,试试不用使用中文的定位方式
(2)可能是谷歌和火狐处理机制有点不一样,会不会是火狐是不是有阻挡层,或这个元素是隐藏的,
所以定位不出来
其他就想不到。具体还是你仔细研究下那个测试的页面吧
页:
[1]