I am using this python selenium code:
from selenium import webdriver
from selenium import webdriver
driver = webdriver.Firefox(executable_path="/home/earth/Downloads/Python/geckodriver-v0.32.0-linux-aarch64 (1)/geckodriver.exe")
driver.maximize_window()
driver.get("https://www.google.com/")
I think your binary version is wrong. You are trying to launch geckodriver.exe which is probably the Windows version of the engine but it seems you are running on Linux.
Use this link to download the geckodriver-v0.32.0-linux64.tar.gz file
from selenium import webdriver
from selenium.webdriver import FirefoxOptions
opts = FirefoxOptions()
opts.add_argument("--headless")
browser = webdriver.Firefox(options=opts)
try using selenium ~=4.4.0, to remove the executable dependency
Related
I've been trying to start using selenium on my laptop, but i just keep getting into errors, after about 1h I'm done trying to fix it by myself.
Selenium version: 3.141.0
chromedriver versoin: 860224
Chrome version: 90.0.4430.11
OS: Arch Linux x86_64
I have this following bit of code(which is copied from the post here:
import selenium
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
options = Options()
options.binary_location = r'/opt/google/chrome-unstable/google-chrome-unstable'
driver = webdriver.Chrome(options= options, executable_path= '/home/andrei399/Downloads/chromedriver_linux64/chromedriver')
driver.get('http://google.com/')
Can anyone please help me? I've been over a lot of stuff, before i restarted my laptop it said it didn't find any binary file, although the path led straight to the x program, I've tried with chrome (not chrome-unstable), although now that doesn't seem to be the problem anymore.
You are using webdriver.Chrome function but you have imported firefox options
Change your code to the following
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.binary_location = r'/opt/google/chrome-unstable/google-chrome-unstable'
driver = webdriver.Chrome(options= options, executable_path= '/home/andrei399/Downloads/chromedriver_linux64/chromedriver')
driver.get('http://google.com/')
I have installed selenium in Ubuntu and by writing this code
from selenium import webdriver
driver = webdriver.chrome()
driver.get("https://google.com")
I have got this output
ImportError: cannot import name webdriver
What should I do?
Selenium is clearly found but wedbdriver can't be imported.
My guess is that you have a file called selenium too, in which case you should name it something else, because python tries to import webdriver from that file rather than the selenium package
I'm having some issues with selenium in my python script.
import time
from selenium import webdriver
browser = webdriver.Chrome(path/to/chromedriver)
After executing the script the terminal is just outputting :
SyntaxError: invalid syntax
the problem is in third line
browser = webdriver.Chrome(path/to/chromedriver)
and I don't really know what to do.
I'm pretty sure that the chrome driver path is correct tho.
I would suggest using the webdriver_manager, as it will take care of downloading the latest stable driver based on the browser version and also takes care of the execution paths.
Use the below 3 simple lines to start the chrome driver.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager``
driver = webdriver.Chrome(ChromeDriverManager().install()
Make sure you have selenium and webdriver_manager libraries added to the project.
Should be, assuming you are on windows
browser = webdriver.Chrome(executable_path=r"C:\path\to\chromedriver.exe")
Or
browser = webdriver.Chrome(executable_path="C:\\path\\to\\chromedriver.exe")
Webdriver download
https://sites.google.com/a/chromium.org/chromedriver/downloads
You can also download and install the chromedriver binary
Just import chromedriver_binary. This will add the executable to your PATH so it will be found.
You can also get the absolute filename of the binary with chromedriver_binary.chromedriver_filename.
from selenium import webdriver
import chromedriver_binary # Adds chromedriver binary to path
driver = webdriver.Chrome()
For Windows:
You have to put the path as a string in quotes "<path to chromdriver>" and would have to use r (for raw) before the string if it only includes single \ e.g. r"C:\Users\user\..." else you don't need it if you path is like "C:\\Users\\user...".
Do:
import time
from selenium import webdriver
browser = webdriver.Chrome(r"<path to chromedriver>")
where "path to chromedriver" is the path to the chromedriver e.g. "C:\Users\<user>\Downloads\chromedriver_win32\chromedriver.exe".
I am playing around with Firefox profiles.
I tried:
from selenium import webdriver
fp = webdriver.FirefoxProfile('C:/Users/<user name>/AppData/Roaming/Mozilla/Firefox/Profiles/abc3defghij2.ProfileName')
driver = webdriver.Firefox(fp)
driver.get("https://www.example.com/membersarea")
As well as
from selenium import webdriver
from selenium.webdriver.firefox.webdriver import FirefoxProfile
profile = FirefoxProfile('C:/Users/Bain3/AppData/Roaming/Mozilla/Firefox/Profiles/g4sh4k5c.fa')
driver = webdriver.Firefox('C:/Users/Bain3/AppData/Roaming/Mozilla/Firefox/Profiles/g4sh4k5c.fa')
driver.get("https://stackoverflow.com/questions/20289598/python-selenium-import-my-regular-firefox-profile-add-ons")
This worked. I then tried to launch it again and now firefox tends to not load any urls. It seems that now when I use
driver = webdriver.Firefox()
driver.get('http://stackoverflow.com')
This does loads the browser but not the url.
I think for some reason adding profiles seems to change the directory of geckodriver. I am using python 3 Anaconda in a virtual env. Changing the system directory, launching geckodriver and Anaconda gecko-driver reinstall do not remedy this.
I thought perhaps changing driver = webdriver. Firefox(executable_path=r'C:\Users\Bain3\Music\geckodriver.exe')(fp)
might help.
Why could I only launch Firefox in a separate profile once and now it simply launches a blank firefox. No error commands in console it's like it's frozen.
Here's an image of Firefox launching.. https://ibb.co/nwnkp5
Thanks
try this...
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('C:/Program Files/Mozilla Firefox/firefox.exe')
driver = webdriver.Firefox(firefox_profile=fp,firefox_binary=binary)
the Argument needs to be: firefox_profile=fp
The binary option can be used to point to different installations/versions of installed Firefox
I'm making a simple web crawler using Python with selenium. (Running on PyCharm Window 10)
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get(http://www.python.org)
I tried various formats for the file Path but all of them seem to return error.
What would be the correct format for the file Path?
P.S. File address I copied off from File Explorer doesn't work either.
Here is the Answer to your Question:
There is no Best Practice to copy/access the driver executable in the Automation Script but on my Windows 8 Pro machine with PyCharm IDE through Python 3.6.1, I explicitly mention the absolute path of the driver executable so that I can work with different versions of different driver executable as well as different Mozilla Firefox versions as follows:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
caps = DesiredCapabilities().FIREFOX
caps["marionette"] = True
driver = webdriver.Firefox(capabilities=caps, firefox_binary=binary, executable_path="C:\\Utility\\BrowserDrivers\\geckodriver.exe")
driver.get('https://stackoverflow.com')
Let me know if this Answers your Question.
address should be within quotes as below.
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("http://www.python.org")