vscode says it run but it does nothing. My pip is up to date and i installed selenium with the command prompt. i have a valid path (i think) for chromedriver. Here's my code:
from selenium import webdriver
chromedriver = "C:Users/P-Lou/Downloads/chromedriver.exe"
driver = webdriver.Chrome(chromedriver)
driver.get("http:google.com")
The result is this:
[Running] python -u "w:\Python\Seletest\app.py"
[Done] exited with code=0 in 0.067 seconds
I tried this code by only changing the browser to firefox and removing the chromedriver = part and it worked fine, you might be running the browser in headless mode, thats why nothing pops up. You can change that using The Chromedriver.options(set_headless="false")
(not sure if that is the right code, you can check yourself here)
Presuming the ChromeDriver binary location being C:\Users\P-Lou\Downloads on your windows system you can use the following solution:
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Users\P-Lou\Downloads\chromedriver.exe')
driver.get("http:google.com")
Related
The relevant code is as follows:
# find the Chromium profile with website caches for the webdriver
chrome_options = Options()
profile_filepath = "user-data-dir=" + "/home/hephaestus/.config/chromium/Profile1"
chrome_options.add_argument(str(profile_filepath))
# put chromium into --no-sandbox mode as a workaround for "DevToolsActivePort file doesn't exist"
chrome_options.add_argument("--no-sandbox")
# start an automatic Chrome tab and go to embervision.live; wait for page to load
driver = webdriver.Chrome("./chromedriver", options=chrome_options)
When I run this Python code (and import the needed libraries), I get the screenshot below. Chromium that was opened with the above code is on the right, and is transparent and glitching out.
Desktop view with Chromium webdriver tab glitching out on the right
I am able to enter web addresses and interact with the page, but I just can't see any of it. I'm not sure why.
I deleted and re-downloaded Selenium and Chromium, to no avail. I had to add the "--no-sandbox" option because it was getting another error that said "DevToolsActivePort file doesn't exist".
I'm not sure what else is causing this issue.
So I found a solution that works for me!
Uninstall and reinstall Chromium completely. When reinstalling, check that your Chromium version matches with Selenium (which I didn't even know was a thing).
DO NOT run your Python code as a sudo user. I did "sudo python3 upload_image.py" and got the "DevToolsActivePort file doesn't exist" error. When I ran just "python3 upload_image.py", it did not raise the error.
Do not use the option "--no-sandbox" when running as a non-sudo user ("python 3 upload_image.py"). For some reason, the "--no-sandbox" option also broke my Chromium browser in the same transparent/infinite way as I posted above.
Hope this helps someone in the future!
I have gone through previous questions but did not find anyone else running into my issue.
This simple code hangs
from selenium import webdriver
d = webdriver.Firefox();
The browser gets launched, but it just hangs there. After sometime, it crashes and I get the error
selenium.common.exceptions.WebDriverException: Message: Can't load the profile.
Profile Dir: /tmp/tmpn_MQnf If you specified a log_file in the
FirefoxBinary constructor, check it for details.
I have Firefox49 on Ubuntu 14.04 LTS. I had selenium 2.53.6 and reading a previous post, I upgraded to selenium 3.0.0.b3. I also downloaded geckdriver and put it in /usr/bin
It looks like I was still running older version of selenium. But when I uninstalled that and installed selenium 3.0.0.b3, I see the following error -
selenium.common.exceptions.WebDriverException:
Message: Service geckodriver unexpectedly exited. Status code was: 2
What am I missing?
Try renaming the downloaded Gecko Driver to Wires and Set the Capabilities as mentioned Below.
System.setProperty("webdriver.gecko.driver", "//home//.....//BrowserDrivers//wires");
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("marionette", true);
Driver = new MarionetteDriver(capabilities);
I tried with the Above code on FireFox 49 on Linux Ubuntu 14.04 LTS... Code Works Fine For Me in Java..
Also try to downgrade the selenium WebDriver from Beta to 2.53 as Beta version is unstable..
I am using Python 3.5 on a Windows computer. When I run this code on my Mac it works perfect, no issues what so ever. But when I bring the code to my Windows computer it doesn't work.
Basically a blank page is shown instead of the home page. I don't get any error messages.
from selenium import webdriver
driver = webdriver.Firefox()
driver.get('https://www.google.com')
cookies = driver.get_cookies()
print(cookies)
Once I close the web browser I get this message in the shell:
"The browser appears to have exited "
selenium.common.exceptions.WebDriverException: Message: The browser appears to have exited before we could connect. If you specified a log_file in the FirefoxBinary constructor, check it for details.
From what I've been able to find online (most is for Java) it looks like I may need to setup a profile? Is this correct and could anyone help with this?
It looks like your client doesn't have the fix for the new switch to launch the gecko driver:
https://github.com/SeleniumHQ/selenium/commit/c76917839c868603c9ab494d8aa0e9d600515371
Make sure that you have the latest beta version installed (selenium-3.0.0b2) if you which to use the geckodriver v0.10.0 and above:
pip install -U selenium --pre
Note that you need the --pre flag to install the beta version.
Using Python 2.7.5, python module selenium (2.41.0) and chromedriver (2.9).
When Chrome starts it displays a message in a yellow popup bar: "You are using an unsupported command-line flag: --ignore-certificate-errors. Stability and security will suffer." This simple example reproduces the problem.
from selenium import webdriver
browser = webdriver.Chrome()
browser.get("http://google.com/")
How do I remove this command-line flag in python selenium?
This extra code removes the --ignore-certificate-errors command-line flag for me. In my opinion the arguments that can be added to webdriver.Chrome() could (and should) be better documented somewhere, I found this solution in a comment on the chromedriver issues page (see post #25).
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["ignore-certificate-errors"])
browser = webdriver.Chrome(chrome_options=options)
browser.get("http://google.com/")
This issue is resolved as of Chromedriver 2.11 (released Oct 2014). Updating will now do the trick.
you can use the following flag --test-type
var options = new ChromeOptions();
options.AddArguments(new[] {
"--start-maximized",
"allow-running-insecure-content",
"--test-type" });
return new ChromeDriver(options);
This is what I'm currently using in Java to get around this issue but I don't know how Python works but worth a try anyway
ChromeOptions chrome = new ChromeOptions();
chrome.addArguments("test-type");
capabilities.setCapability(ChromeOptions.CAPABILITY, chrome);
capabilities.setCapability("chrome.binary",
"C:\\set path to driver here\\chromedriver.exe");
options = webdriver.ChromeOptions()
options.add_argument('test-type')
chromedriver = 'resources/chromedriver.exe'
os.environ["webdriver.chrome.driver"] = chromedriver
self.driver = webdriver.Chrome(chromedriver,chrome_options=options)
I was having this problem using Selenium2 with Robot on a Mac. The problem ended up being that I had the wrong version of chromedriver installed on my system...
$ chromedriver
Starting ChromeDriver (v2.9.248307) on port 9515 <<Version 2.9 was the problem
I found it in /usr/local/bin and just removed it and replaced it from the official download page and it seems to have cleared it all up...
$ chromedriver
Starting ChromeDriver 2.25.426935 (820a95b0b81d33e42712f9198c215f703412e1a1) on port 9515
Only local connections are allowed.
I've used Firefox with Webdriver on this machine before, but suddenly when I use any code that utilizes Firefox as the driver, Firefox will open and just sit there blankly. Absolutely nothing loads, my program hangs until I close the window at which point it raises the "browser not open" error.
Tried reinstalling. Chrome/IE Drivers work but I don't really want to use them.
Included a pic of exactly what happens when I use any code, for instance
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
url = "http://google.com"
driver.get(url)
Even this gets me nothing.
upgrade to selenium version 2.29.0
pip install -U selenium
there was a bug fix in the previous version