Selenium node crashes shortly after opening

272 Views Asked by At

I am trying to do simple web testing with Selenium hub/node connection. Idea is to make some tests in Katalon IDE and then export them into python for the node to run. So I made my first test case, exported it to python and run it on standalone selenium node and it worked great.

Unfortunately, this test doesn't work if I try to run it from the hub to the node. It opens the node web browser on the starting page but it crashes shortly after, without doing anything from the test. I tried Firefox and chrome but I get the same results. I am not good with python so I apologize if there is an easy fix I didn't see it myself.

Here is my testcase:

    # -*- 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 OKGoogle(unittest.TestCase):


    def setUp(self):
        self.driver = webdriver.Remote(
            command_executor = 'http://192.168.1.244:4444/wd/hub',
            desired_capabilities = {
            'browserName': 'firefox',
            'javascriptEnabled': True
            })


    def test_o_k_google(self):
        driver = self.driver
        driver.get("https://www.google.com/")
        driver.find_element_by_id("lst-ib").clear()
        driver.find_element_by_id("lst-ib").send_keys("ok google")
        driver.find_element_by_id("lst-ib").send_keys(Keys.ENTER)
        driver.find_element_by_xpath("(.//*[normalize-space(text()) and normalize-space(.)=concat('Use ', '\"', 'Ok Google', '\"', ' voice searches & actions - Android - Google Search ...')])[1]/following::cite[1]").click()

    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()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()

And the error I get:

Traceback (most recent call last):
  File "OKGoogle.py", line 25, in test_o_k_google
    driver.find_element_by_id("lst-ib").clear()
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 360, in find_element_by_id
    return self.find_element(by=By.ID, value=id_)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 978, in find_element
    'value': value})['value']
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: Unable to locate element: [id="lst-ib"]


======================================================================
ERROR: test_o_k_google (__main__.OKGoogle)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "OKGoogle.py", line 53, in tearDown
    self.assertEqual([], self.verificationErrors)
AttributeError: 'OKGoogle' object has no attribute 'verificationErrors'

----------------------------------------------------------------------
Ran 1 test in 10.453s

FAILED (errors=2)

Any help is very much appreciated.

0

There are 0 best solutions below