0

I've got autotests, using Chromedriver, and locally they work well in a graphical mode. We're gonna run them on ubuntu server without graphic, so I need to use another driver or emulate X-server. I'm trying to use PhantomJs. Below is what I've done:

1) Downloaded the latest 2.1.1 PhantomJs drive and put it in the PATH variable. 2) Tests are working using Selenium 3.3.1, pytest 2.9.0 3) Changed the driver in my tests:

#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()

So, when i run tests, I see:

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

What I did wrong? Maybe it's the problem with this version of Phantom? Would be great to hear any ideas to solve the problem.

  • It might be related to `SessionHelper` class in `fixture/session.py`, sounds like it is trying to find element with id `LoginLogin`, which is not present on the login page? – hurturk Apr 05 '17 at 03:59
  • @hurturk Class SessionHelper includes loginn method: ` class SessionHelper: def __init__(self, app): self.app = app def login(self, username, password): wd = self.app.wd self.app.open_home_page() wd.find_element_by_id("LoginLogin").send_keys(username) wd.find_element_by_id("LoginPassword").send_keys(password) wd.find_element_by_xpath("//div[@class='login-body']/form/button").click() ` It's in the login page and it do login in a graphical mode. – Александр Бобров Apr 05 '17 at 04:03
  • Could you put a `import pdb; pdb.set_trace()` just before first `send_keys` and enter `wd.page_source` to see if login element is there? It is possible that username input's ID might have changed from `LoginLogin` to something else. You might be not getting home page properly at all (e.g. redirect or internally unavailable). – hurturk Apr 05 '17 at 04:08
  • You can also get a screenshot at this point by: `wd.save_screenshot("path/to/screen.jpeg")` – hurturk Apr 05 '17 at 04:12

0 Answers0