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
Related
I am not able to figure out why selenium API's are not executing in chrome browser, while chromedriver and chrome version is identical.
Chromedriver Version -> 91.0.4472.19
Chrome Version-> 91.0.4472.124
Output: Chrome launches and "data;" comes written in URL Bar. Nothing happens after that and test continues in running state.
I have tested with chromedriver 89,90,91,92. But nothing seems to be working.
Have anyone faced this issue ever where chrome and chromdriver version were same but browser is not executing selenoum API?
Code:
Browser name is passed from testngXML file.
ChromeOptions options = new ChromeOptions ();
options.setBinary("C\\ProgramFiles(86)\\..\\chrome.exe"); (in this location, I have chrome 91)
.......
......
System.setProperty("webdriver.chrome.driver", "src\\main\\resources\\chromedriver.exe"); (Here I have chromedriver 91)
This issue was related to somehow chrome policies. In my corporate system, there was a policy adding in chrome browser from admin (In every 1 hour) which was marking "disableChromeDevToolBar" as true. This was making the inspect (ctrl+shift+I) also greyed out.
I tried to fix this part, by changing the "disableChromeDveToolBar" value from 1 to 0 ([Windor+r-> regedit-> HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Google\Chrome]).
This made the inspect and selenium API execution working in the chrome browser.
Note: I did not do any change in chrome browser and chromedriver. Issue was purely because of this policy.
Trying to get that policy detail from support team, if I can find out, I will update here.
"Using Selenium on PythonAnywhere" says:
Firefox only, selenium 2, geckodriver not required (…)
That (Firefox v17.0) is quite an old version, but it
works for most sites.
In my case it did not work. Is there a way to use Google Chrome (headless) anyway on PythonAnywhere?
I found this forum entry with the hint that it is not only possible to use Chrome, but even "You'll need to upgrade Selenium to the most recent version".
I simply wrote an email to the PythonAnywhere support and they enabled that for my (payed) account within hours.
Don't forget to start a new console or restart your web app! Then the following code should work:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
browser = webdriver.Chrome(options=chrome_options)
try:
browser.get("https://www.google.com")
print(f'Page title was {browser.title}')
finally:
browser.quit()
I'm using Selenium webdriver with Google Chrome. This is the code I was using to set the proxy for chrome:
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=%s' % my_proxy)
This code worked for months. I'm coming back now and it is not working... I've tried older versions of Selenium, Chrome, Chromium, and the webdriver. None of the changes I do seem to work :(
Additionally, running chrome.exe from the command line while passing --proxy-server does not work! Chrome silently ignores the passed proxy...
Does anyone have any idea what is going on here? I've spent days trying to figure out how to get this simple selenium script working... Thanks so much :)
EDIT: I just tried running chrome.exe with the --proxy-server flags on a friend who has the same computer as mine and it worked...
This was one of the chrome extensions I had installed... If chrome.exe --proxy-server=xxx is not working try removing all extensions.
Hopefully no one else has to waste 3 days on this :(
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
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!