if __name__ == '__main__':
driver=webdriver.Firefox(executable_path=r'/home/saurabh/Saurabh/LearnPython/Automation/geckodriver');
After running the above code I am getting an error as :
selenium.common.exceptions.WebDriverException: Message: Unable to find a matching set of capabilities
I don't see any significant error in your code as such.
It is to be noted that the current Selenium-Python binding is unstable with geckodriver and looks to be Architecture specific. You can find the github discussion and merge here. So you may additionally need to pass the absolute path of the firefox binary as firefox_binary argument while initializing the webdriver
Here is your own code with a simple tweak which opens the Mozilla Firefox browser:
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
if __name__ == '__main__':
binary = FirefoxBinary('C:\\Program Files\\Mozilla Firefox\\firefox.exe')
driver = webdriver.Firefox(firefox_binary=binary, executable_path="C:\\path\\to\\geckodriver.exe")
Make sur you are pointing to \path\to\FirefoxPortable\App\Firefox64\firefox.exe and not just \path\to\FirefoxPortable\FirefoxPortable.exe
Related
so I have started working on selenium, and this is my first time working with it, the code provided below opens chrome but doesnt open the url mentioned in the .get function.
from selenium import webdriver
import time
# open chrome and access the page
driver = webdriver.Chrome("C:\Program Files\Google\Chrome\Application\chrome.exe")
driver.get('https://dex.onxrp.com/?project=XREEFS')
time.sleep(5)
driver.close()
I have installed the selenium pip library, do i need something else as well for it to load the link?
Using selenium3 the default argument which can be passed within webdriver.Chrome() is the value of the KEY executable_path i.e. the logical/absolute path of the ChromeDriver executable but not of google-chrome executable.
Solution
Ideally, your line of code will be:
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe')
I am a complete beginner to selenium and I wrote my first program just to connect to Google.
from selenium import webdriver
path = "C:\\Users\\Home\\Documents\\Python37-32\\Scripts\\Code\\msedgedriver.exe"
driver = webdriver.Edge(path)
driver.get("https://google.com")
print(driver.title)"
My web driver version is 88.0.705.50 (Official build) (64-bit)
I use selenium 3 and I am getting this error while running the code. Also it is opening "data:," for a few seconds then opening Google. Lastly the browser doesn't stay open.
Declare path on a separate line from the import statement
Use raw string in path or double escapes
Code:
from selenium import webdriver
path = r"C:\Users\Home\Documents\Python37-32\Scripts\Code\msedgedriver.exe"
driver = webdriver.Edge(path)
driver.get("https://google.com")
print(driver.title)
What error do you get? It's the default behavior that the browser opens with data:,, then it will direct to the website you want. The browser doesn't stay opened may because the error breaks it.
You can refer to the following steps to automate Edge in python selenium:
Make sure the WebDriver version is the same as the Edge version.
Install the MS Edge Selenium tools using command below:
pip install msedge-selenium-tools selenium==3.141
Sample code:
from msedge.selenium_tools import Edge, EdgeOptions
options = EdgeOptions()
options.use_chromium = True
driver = Edge(executable_path = r"C:\Users\Home\Documents\Python37-32\Scripts\Code\msedgedriver.exe", options = options)
driver.get("https://google.com")
print(driver.title)
When I am passing fully qualified path for the executable_path the Chrome() method able to locate the driver but when I am creating a directory(drivers) inside the project in pycharm and passing as
driver = webdriver.Chrome(executable_path="../drivers/chromedriver")
then Chrome() method fails to locate.
According to me, error reason would be:
1) chromedriver copied into the local directory is not supporting.(Getting a question mark on the copied chromedriver executable file)
2) Proper path is not passed
Image Of My Structure & Error Image
Try This:
pip install webdriver_manager
Then:
from webdriver_manager.chrome import ChromeDriverManager
from selenium import webdriver
driver = webdriver.Chrome(ChromeDriverManager().install())
When using a relative path, it needs to include the r to specify it's raw. Also, include the .exe in the path for the driver.
For example,
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'../drivers/chromedriver.exe')#Use single quotation mark
Apply the same changes to yours and it should solve your problem.
Try To add one dot
Try This:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="./driver/chromedriver")
dealing with paths can be a bit tricky, i always use a lib
import pathlib
from selenium import webdriver
driver = webdriver.Chrome(executable_path=str(pathlib.Path().absolute().parent.joinpath('drivers').joinpath('chromedriver'))))
hope it helps.
I tried to add adblock to the selenium using this code:
chop =webdriver.ChromeOptions()
chop.add_extension('Adblock-Plus_v1.4.1.crx')
driver = webdriver.Chrome(chrome_options=chop)
I got this error:
'OSError: Path to the extension doesn't exist'
what should I do?
You need to provide the full path:
from os import path
chop =webdriver.ChromeOptions()
chop.add_extension(path.abspath('Adblock-Plus_v1.4.1.crx'))
driver = webdriver.Chrome(chrome_options=chop)
I'm trying to scrape some data from a URL with dynamic content and learned Selenium can do the task.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary('/Applications/Firefox.app/Contents/MacOS')
driver = webdriver.Firefox(firefox_binary=binary)
The 4 lines above gives me
OSError: [Errno 13] Permission denied
I googled and seems that others have encountered similar issues but none of the solutions I found work. Some seem to be for Windows and others seem to be for Java rather than Python.
When running your code, I got the same error. But, if you just want to use selenium to open up Firefox browser and go from there, simply use this:
from selenium import webdriver
browser = webdriver.Firefox()
browser.get("http://www.google.com")
It will trigger an initial web browser and open up a webpage.
The following line causes the problem:
binary = FirefoxBinary('/Applications/Firefox.app/Contents/MacOS')
Make sure to provide the correct path of the binary on the filesystem, not in your application launcher, i.e.
binary = FirefoxBinary('/usr/bin/firefox')