我使用Chromedriver获得了自动测试,并且在本地他们在图形模式下运行良好。我们将在没有图形的ubuntu服务器上运行它们,所以我需要使用另一个驱动程序或模拟X服务器。我试图使用PhantomJs。以下是我所做的:
1)下载最新的2.1.1 PhantomJs驱动器并将其放入PATH变量中。 2)使用Selenium 3.3.1,pytest 2.9.0进行测试 3)在我的测试中更改了驱动程序:
#from selenium.webdriver.chrome.webdriver import WebDriver
from selenium.webdriver.phantomjs.webdriver import WebDriver
from fixture.session import SessionHelper
from fixture.new_house import NewHouseHelper
from fixture.rooms import RoomsHelper
class Application:
def __init__(self):
self.wd = WebDriver()
self.wd.implicitly_wait(20)
self.wd.maximize_window()
# Помощник получает ссылку на объект класса application
self.session = SessionHelper(self)
self.new_house = NewHouseHelper(self)
self.rooms = RoomsHelper(self)
def is_valid(self):
try:
self.wd.current_url
return True
except:
return False
def open_home_page(self):
wd = self.wd
wd.get("my_url")
def destroy(self):
self.wd.quit()
所以,当我运行测试时,我看到:
E selenium.common.exceptions.NoSuchElementException: Message: {"errorMessage":"Unable to find element with id 'LoginLogin'","request":{"headers":{"Accept":"application/json","Accept-Encoding":"identity","Connection":"close","Content-Length":"91","Content-Type":"application/json;charset=UTF-8","Host":"127.0.0.1:62719","User-Agent":"Python-urllib/3.5"},"httpVersion":"1.1","method":"POST","post":"{\"using\": \"id\", \"sessionId\": \"0d199430-19b3-11e7-8517-21c763e93303\", \"value\": \"LoginLogin\"}","url":"/element","urlParsed":{"anchor":"","query":"","file":"element","directory":"/","path":"/element","relative":"/element","port":"","host":"","password":"","user":"","userInfo":"","authority":"","protocol":"","source":"/element","queryKey":{},"chunks":["element"]},"urlOriginal":"/session/0d199430-19b3-11e7-8517-21c763e93303/element"}}
E Screenshot: available via screen
..\env\lib\site-packages\selenium\webdriver\remote\errorhandler.py:193: NoSuchElementException
我做错了什么?也许是这个版本的Phantom的问题?很高兴听到任何解决问题的想法。