Jenkins not able to open a firefox window selenium (python ) - python

I'm able to run my Python code(main.py) perfectly alright.The problem happens when I use Jenkins to run my Python code( main.py). Jenkins is not able to launch Firefox.
The line
driver = webdriver.Firefox() is throwing an exception line this:
Entering main()
Traceback (most recent call last):
File "main.py", line 21, in <module>
driver = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 59, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 47, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 61, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 100, in _wait_until_connectable
self._get_firefox_output())
selenium.common.exceptions.WebDriverException: Message: "The browser appears to have exited before we could connect. The output was: \n(process:9287): GLib-CRITICAL **: g_slice_set_config: assertion `sys_page_size == 0' failed\nError: no display specified\n"
Finished: SUCCESS
############# Code snippet ###########
if __name__ == __main__ :
driver = webdriver.Firefox()
driver.implicitly_wait(10)
driver.get("www.google.com")

Are you on windows platform and running Jenkins as a windows service?
If so then the remedy will be to run the Jenkins from the command line.

Related

Control Vivaldi browser

I want to manage the tabs of Vivaldi (Windows) using Python: get URLs, focus a specific tab, open, close, reload...
This post asks how to open Vivaldi, and my script does it, but not when/how it's supposed to do it:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import os
current_user = os.getlogin()
s = Service(rf"C:\Users\{current_user}\AppData\Local\Vivaldi\Application\vivaldi.exe")
driver = webdriver.Chrome(service=s)
The last line opens a new (unwanted) window of Vivaldi, which baffles me because I thought it should only declare a variable, and then nothing happens for some minutes. Finally I get this error:
Traceback (most recent call last):
File "C:\Users\Negozio\Dropbox\D.Apps\Negozio\Conta\test.py", line 7, in <module>
driver = webdriver.Chrome(service=s)
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 70, in __init__
super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\chromium\webdriver.py", line 90, in __init__
self.service.start()
File "C:\Program Files\Python310\lib\site-packages\selenium\webdriver\common\service.py", line 105, in start
raise WebDriverException("Can not connect to the Service %s" % self.path)
selenium.common.exceptions.WebDriverException: Message: Can not connect to the Service C:\Users\Negozio\AppData\Local\Vivaldi\Application\vivaldi.exe
I thought that Vivaldi should open with driver.get("http://url.com"), am I wrong? What's happening here, and above all how can I manage Vivaldi with Python?

AttributeError: can't set attribute in appium-python

import time
import unittest
from appium.webdriver.webdriver import WebDriver as AppiumDriver
from appium import webdriver
desired_caps = dict(
platformName='Android',
deviceName='Android Emulator',
app=('C:/Users/Asus/Desktop/h.a/asan.apk')
)
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
i recieved this error: appium-python
i got this message:
how can i fix it?
am using appium and android studio emulator to simulate and automation test of android application.
Traceback (most recent call last):
File "C:\Users\Asus\workspace\top web\complete.py", line 19, in <module>
driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
File "C:\Users\Asus\AppData\Local\Programs\Python\Python39\lib\site-packages\appium\webdriver\webdriver.py", line 151, in __init__
super().__init__(
File "C:\Users\Asus\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 268, in __init__
self.start_session(capabilities, browser_profile)
File "C:\Users\Asus\AppData\Local\Programs\Python\Python39\lib\site-packages\appium\webdriver\webdriver.py", line 229, in start_session
self.capabilities = response.get('value')
AttributeError: can't set attribute
I had this same issue and it got fixed by re-installing appium with python instead of npm.
I installed appium from source https://github.com/appium/python-client

Python - Selenium: selenium.common.exceptions.WebDriverException

Working at a company so could be too do with firewall permissions ect, but I am able to modify objects in the same location as the .exe. I have the code below. The chrome session opens and maximises but does not go to the webpage or enter any elements.
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Users\ME\Local\Google\Chrome\Application\chrome.exe')
driver.maximize_window()
driver.get("http://www.seleniumeasy.com/test/basic-first-form-demo.html")
assert "Selenium Easy Demo - Simple Form to Automate using Selenium" in driver.title
eleUserMessage = driver.find_element_by_id("user-message")
eleUserMessage.clear()
eleUserMessage.send_keys("Test Python")
eleShowMsgBtn=driver.find_element_by_css_selector('#get-input > .btn')
eleShowMsgBtn.click()
eleYourMsg=driver.find_element_by_id("display")
assert "Test Python" in eleYourMsg.text
driver.close()
But keeps exiting with the error:
C:\Users\ME\MyNewEnv\Scripts\python.exe "F:/Sam/TASKS/xings.py"
Traceback (most recent call last):
File "F:/Sam/TASKS/xings.py", line 3, in <module>
driver = webdriver.Chrome(executable_path=r'C:\Users\ME\Local\Google\Chrome\Application\chrome.exe')
File "C:\Users\ME\MyNewEnv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
self.service.start()
File "C:\Users\ME\MyNewEnv\lib\site-packages\selenium\webdriver\common\service.py", line 98, in start
self.assert_process_still_running()
File "C:\Users\ME\MyNewEnv\lib\site-packages\selenium\webdriver\common\service.py", line 111, in assert_process_still_running
% (self.path, return_code)
selenium.common.exceptions.WebDriverException: Message: Service C:\Users\ME\Local\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
Process finished with exit code 1
You should use chromedriver in executable_path instead of chrome.
You can download chromedriver from https://chromedriver.chromium.org/downloads
After downloading you can do
driver = webdriver.Chrome(executable_path=r'path/to/chromedriver')

KeyError: 'value' while running headless browser testing using robotframework xvfb module

I am trying to run headless browser testing using robot framework on my ubuntu machine . Following is the error that i am getting whenever i execute the script.Can someone guide how to fix this error.
*** Settings ***
Documentation This example demonstrates how to use current library
Library Selenium2Library
Library XvfbRobot
*** Test Cases ***
Create Headless Browser
Start Virtual Display 1920 1080
Open Browser https://www.google.com
Set Window Size 1920 1080
${title}= Get Title
Should Be Equal Google {title}
[Teardown] Close Browser
root#hyi01lr0bsaehost92:/var/robot-tests# pybot headless.robot
==============================================================================
Headless :: This example demonstrates how to use current library
==============================================================================
[ WARN ] Keyword 'Capture Page Screenshot' could not be run on failure: No browser is open
Create Headless Browser | FAIL |
KeyError: 'value'
------------------------------------------------------------------------------
Headless :: This example demonstrates how to use current library | FAIL |
1 critical test, 0 passed, 1 failed
1 test total, 0 passed, 1 failed
==============================================================================
Output: /var/robot-tests/output.xml
Log: /var/robot-tests/log.html
Report: /var/robot-tests/report.html
I have tried with Python script as well but with that also i am getting same error.
#!/usr/bin/env python
from pyvirtualdisplay import Display
from selenium import webdriver
display = Display(visible=0, size=(800, 600))
display.start()
# now Firefox will run in a virtual display.
# you will not see the browser.
browser = webdriver.Firefox()
browser.get('http://www.google.com')
print browser.title
browser.quit()
display.stop()
root#hyi01lr0bsaehost92:/var/robot-tests# python seleniumheadless.py
Traceback (most recent call last):
File "seleniumheadless.py", line 13, in <module>
browser = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 155, in __init__
keep_alive=True)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 183, in start_session
self.capabilities = response['value']
KeyError: 'value'
Got following error when tried with webdriver.Chrome()
root#hyi01lr0bsaehost92:/var/robot-tests# python seleniumheadless.py
Traceback (most recent call last):
File "seleniumheadless.py", line 11, in <module>
browser = webdriver.Chrome()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/chrome/webdriver.py", line 69, in __init__
desired_capabilities=desired_capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: chrome not reachable
(Driver info: chromedriver=2.26.436382 (70eb799287ce4c2208441fc057053a5b07ceabac),platform=Linux 3.13.0-119-generic x86_64)
root#hyi01lr0bsaehost92:/var/robot-tests# which google-chrome
/usr/bin/google-chrome

Selennium Python can't load the profile Iceweasel

I am trying to run Selenium from the command line with Python. I have ice weasel installed n a raspberry pi. This is my code to initialise it:
from selenium import webdriver
from pyvirtualdisplay import Display
display = Display(visible=0, size=(800, 600))
display.start()
driver = webdriver.Firefox()
However, whenever I try to run the file, I get the following error:
Traceback (most recent call last):
File "Minecraft.py", line 5, in <module>
driver = webdriver.Firefox()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 77, in __init__
self.binary, timeout),
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/extension_connection.py", line 49, in __init__
self.binary.launch_browser(self.profile)
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 68, in launch_browser
self._wait_until_connectable()
File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/firefox_binary.py", line 103, in _wait_until_connectable
raise WebDriverException("Can't load the profile. Profile "
selenium.common.exceptions.WebDriverException: Message: Can't load the profile. Profile Dir: %s If you specified a log_file in the FirefoxBinary constructor, check it for details.

Categories

Resources