Firefox runs in background in Selenide - selenium

usually, questions are in opposite way, how to make a Firefox run to be in the background. I have written some time ago some basic tests in Selenide, but when today I tried to run it (as usual) on a server, I got an error
SessionNotCreatedException
I started to look for the result and I noticed, that when I'm running now tests locally from my computer, Firefox does not appear. I can see Firefox's tasks in Task manager, I got an error with a done screenshot, but the browser does not open.
I noticed there is plenty of questions about how to run tests with the headless option, but I need something opposite, this might be a problem with SessionNotCreatedException, the server does not see the browser.
As I know Selenide runs the newest gecko driver (it's updating). I tried to set some options in the beginning:
FirefoxOptions options = new FirefoxOptions();
options.setCapability("marionette", false);
options.setCapability("headless", false);
and also updated Selenide to 5.0.0, but it's still failing
EDIT: I can't use any other browsers

For running tests on a server generally, the server is an X window system so the way to do it is to run a virtual display.
Using Xvfb is the best way for that! you can read about it here.
from xvfbwrapper import Xvfb
with Xvfb() as xvfb:
# launch virtual display here.
# start your webdrivr in the virtual display
Or you can use PyVirtualDisplay link here.
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()
Note
Make sure your server is an X Window System!
As you can see here it doesn't work on windows.
Hope this helps you!

Related

New error discovered when using Chromedriver Selenium

When I try to open Chrome with selenium with webdriver, it shows a chrome that looks like this.
Even though it's been a long wait, it's still the same. While I open it by right clicking, it works fine.
I've tried using all versions of Chromedriver 100 and 99, but the results haven't changed much.
Here is the source code that I use:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument(f"--user-data-dir=G:\\Multi_Chrome\\testing\\Data\\profile")
driver = webdriver.Chrome(service=Service("D:\\Python\\Project\\chromedriver.exe"),
options=chrome_options)
input("Press any key to coutinue ...")
driver.close()
driver.quit()
Any ideas? By the way, I want to ask more, how to open a normal portable chrome. Instead of right clicking and choosing open. Is there a way to automatically open it?
I have partially mentioned it in this article: Open a complete portable chrome like regular Chrome
your question isn't clear because you didn't mention what is the error, but as I see in the screenshot you have already opened one chrome browser before you run the script, but you use --user-data-dir=G:\\Multi_Chrome\\testing\\Data\\profile it means that this profile is already is in use so you cant open another chrome browser with the same profile. so The simplest and easiest fix is to close all running chrome browsers and after that try to run your script again

Running chrome via selenium

I did it earlier but I can't use chrome via selenium now. Browser opens for a few seconds then closes and then I got an error (about 5 minutes later):
Message: session not created
from disconnected: unable to connect to renderer
(Session info: chrome=70.0.3538.67)
(Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.18.14-arch1-1-ARCH x86_64)
I use following code for running browser (which I always use):
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.options import Options
opts = Options()
browser = Chrome(options=opts)
Chromedriver directory is in the PATH. Versions of chrome and chromedriver you can see in the error. Python 3.7.0, selenium==3.14.0. What's wrong in my actions?
P.S. BTW, It works fine with Firefox
Your versions look compatible with each other based on the compatibility list, so I don't think it has to do with that. I have not seen those options used in that way before though.
Please try this:
from selenium import webdriver
ChromeOptions = webdriver.ChromeOptions()
browser = webdriver.Chrome(chrome_options=ChromeOptions)
browser.get("https://www.google.com")
browser.quit()
Let me know if that is able to open your browser. If it is, then I am assuming you are having issues with some of the options you are passing chrome.
If you are still have issues after checking all the options you are passing chrome, try rolling back your chromedriver version HERE to 2.42. It should still be compatible with chromer version 70.-.
I am on the same versions as you, and I'm not experiencing this issue.
A couple other things to think about:
Are you using headless chrome? If so switch to non-headless and test.
Make sure to close out of all instances of chromedriver before updating with another version.
If chrome recently updated, or you recently updated your driver, try
restarting the machine.
Actually I don't know why, but it works fine now. Everything I did are recommendations from the answer above. It didn't work right after my actions but now it's okay

Selenium IE Webdriver send slowkeys even though changed to 32Bit

I have a serious Problem, and i tried about 20 workarounds which completely failed to work as a solution for me.
MainProblem: I execute a testsuite parallel on 3 different browsers, Chrome, Firefox and IE11. While sendKeys() works perfectly fine on chrome and Firefox, on IE every letter takes about 5 seconds to appear, so a normal login-procedure which takes about 2 sec on chrome takes about 50 on IE...
I work on a mac. On the Mac, i have a WindowsPC (Win10) in a VM via Parallels. On this, i installed JDK, Eclipse, and try to automate a webpage via Selenium+Testng.
IE Version: 11.192.16299.0
I set the security level to low for trusted and local intranet, i removed the save-mode checkbox. I got the well known slow-sendKeys-Problem. But for most of the internet it worked with changing the IEWebdriver from 64-> 32Bit. It simply doesnt make any difference and i struggle here.
I really need help. Please let me know if you need any insight, logs or whatever, i try to provide with everything fast.
Best Greets!
By setting up the following options It should resolve the problem:
System.setProperty("webdriver.ie.driver", "./path/IEDriverServer.exe");
InternetExplorerOptions options = new InternetExplorerOptions();
options.introduceFlakinessByIgnoringSecurityDomains();
options.requireWindowFocus();
WebDriver driver = new InternetExplorerDriver(options);

WebDriverException: Element is not clickable at point

Complete error
org.openqa.selenium.WebDriverException: Element is not clickable at
point (931, 23). Other element would receive the click:
Running selenium tests using Jenkins in headless browser
In following environment
OS- CentOS 6 and Xvfb installed in same machine
Xvfb screen resolution - Xvfb :1 -screen 0 1280x1024x16 &
Driver - Firefox driver
Selenium webdriver version - 2.52.0
The same test case working fine in windows os with firefox
Try this. Install Xvfb plugin on Jenkins.
After that install Xvfb in "Global Tool Configuration"
Then under your project configuration, setup xvfb
Try Using resolution given in image
Now run your build :)
This is the reason it is important to test on different browsers and on different platforms. Sometimes what works on one browser/os does not work on the same browser but a different platform.
I would update your setup so that you make a screenshot when you run into this type (and most other types) of error. In my experience this is the single best thing you can do to reduce the time spent to debug these issues.
In my setup I do the following:
Create a screenshot
Capture the coordinates from the Selenium error message
Use an image manipulation program to automatically create a red dot where the click happened
Usually I just have to take one look at such an image to see exactly what is happening.

A GUI to debug phantomjs script

I am using phantomjs to build a web crawler. My current crawler is a Python script using selenium, which requires a running Firefox browser. While Selenium is good for debugging scripts (as I can use firebug to inspect the webpage), it cannot be deployed on linux servers without GUI. So I am trying to translate my Python script to phantomjs.
To debug phantomjs scripts, I save the page source html and render a png screenshot to disk, and open it in Firefox to inspect the source page. I am wondering if there is a better way to do this, e.g. a plugin for phantomjs, etc.
This little hack is using a simple technique: It grabs the screen as PhantomJS or CasperJS sees it with captureBase64('png') and then it is POSTing the image into the receiving server which then sends it via socket.io to the browser which displays it is as inline image.
The source code is available on github:
https://github.com/maciejjankowski/flaming-octo-puss
I'm not sure if PhantomJS has it, but CasperJS does (and the latter adds some extra functions to PhantomJS)
and use remote debugging as others suggest
As for most of the JS scripts, it's not so trivial to debug phantomjs script, because there is no IDE/compiler behind this.
First, I higly suggest you to read the Troubleshooting section.
As said by torazaburo, your best option is to use Remote Debugging : scripts can be run in a Web Inspector interface-like console : step-in, step-out, break points, local variables... many classic debugger features are available. If you're familliar with Chrome developpers tools, it's pretty the same.
Though not a solution to your Phantomjs troubles,I think Selenium with Python bindings can be used very efficiently as a headless scraper in a Linux environment.
You can use PyVirtualDisplay, a Python wrapper for Xvfb and Xephyr to fake a display.PyVirtualDisplay needs Xvfb as a dependency. On Ubuntu, first install Xvfb:
sudo apt-get install xvfb
then install PyVirtualDisplay from Pypi:
pip install pyvirtualdisplay
Sample Selenium script in Python in a headless mode with PyVirtualDisplay:
#!/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()