Python Selenium show geckodriver version - python

How can I find out which version of geckodriver I use?
from selenium import webdriver
driver = webdriver.Firefox()
Not sure if the new one is used or the old one when I use:
sys.path.append(self.driver_dir)
Thanks in advance
http://selenium-python.readthedocs.io/api.html

You can get capabilities of driver by below code:
from selenium import webdriver
driver = webdriver.Firefox()
print driver.capabilities
It will print driver related info in dictionary form, which would also have info about driver version.

Related

'WebDriver' object has no attribute 'Chrome'

I'm new here and new to coding. I'm trying to run:
wd = wd.Chrome()
wd.implicity_wait(10)
But I keep getting an error that reads
AttributeError: 'WebDriver' object has no attribute 'Chrome'
Here's a picture of what I have so far
Can anybody help me out.
first check google chrome version of your system by using this in URL chrome://version/
then download chrome driver from below mention website according to chrome version https://chromedriver.chromium.org/downloads
then type this in pycharm or sublime text
import selenium
from selenium import webdriver
driver = webdriver.chrome.webdriver.WebDriver(executable_path='C:/drivers/chromedriver_win32 (1)/chromedriver.exe')
driver.get("http://www.python.org")
Or
from selenium import webdriver
driver = webdriver.Chrome()
perhaps you wanna do this instead :
from selenium import webdriver
driver = webdriver.Chrome(r'C:\\Users\\Automation\\chromedriver.exe')
or in case you want to initiate with ChromeOptions, you can do it like this
from selenium import webdriver
options = webdriver.ChromeOptions()
driver = webdriver.Chrome(r'C:\\Users\\Automation\\chromedriver.exe', options = options)
You should give your chromedriver.exe file location in place of C:\\Users\\Automation\\chromedriver.exe

Error in python selenium 3 Edge web driver

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)

How to initiate a Chromium based Vivaldi browser session using Selenium and Python

I am trying to use the vivaldi browser with Selenium. It is a chromium browser that runs very similar to chrome. I have Selenium working with Firefox (geckodriver), and Google Chrome(chromedriver), but I can't seem to find a way with Vivaldi. Any help would be appreciated.
If the vivaldi binary by default is located at C:\Users\levir\AppData\Local\Vivaldi\Application\vivaldi.exe you can use the following solution:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_argument("start-maximized")
options.binary_location=r'C:\Users\levir\AppData\Local\Vivaldi\Application\vivaldi.exe'
driver = webdriver.Chrome(executable_path=r'C:\path\to\chromedriver.exe', options=options)
driver.get('http://google.com/')
For future reference:
to make Vivaldi work with selenium you need to make sure of three things :
The correct version of ChromeDriver
Set selenium's driver to use Vivaldi's binary via webdriver.ChromeOptions()
Make sure you're getting the correct url (don't forget "https://")
All of the above is explained step by step with screenshots in this blog post
The key executable_path will be deprecated in the upcoming releases of Selenium.
This post has the solution. I'm posting a copy of said solution with the path to Vivaldi, where the username is fetched by the script so you don't have to hard code it.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import os
current_user = os.getlogin()
s = Service(rf"C:\Users\{current_user}\AppData\Local\Vivaldi\Application\vivaldi.exe")
driver = webdriver.Chrome(service=s)
driver.get("http://duckduckgo.com") # or your website of choice
You can use ChromeOptions and supply binary.
from selenium.webdriver.chrome.options import Options
opt = Options()
opt.binary_location = chromium_path//path to chromium binary
driver = webdriver.Chrome(options=opt, executable_path="path_to_chromedriver")

How to load a existing FirefoxProfile through Selenium and Python

First time posting here, so I address a problem I cannot solve.Checked Stackoverflow and google. There's some answers for java which I couldn't decode. Therefore you might mention that this is a duplicate, but so far no one answered such a question.
Any ideas will be really appreciated.
from selenium import webdriver
from selenium.webdriver.firefox.firefox_profile import FirefoxProfile
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
binary = FirefoxBinary(r'C:\Program Files (x86)\MozillaFirefox\firefox.exe')
profile = FirefoxProfile(r'C:\Users\User\Documents\dxcwavid.Zydrius5')
driver = webdriver.Firefox(firefox_profile = profile, firefox_binary = binary)
driver.get("http://google.com")
geckodriver: 0.23.0
python: 3.7.1
selenium: 3.141.0
Windows: 10 1511
Try with:
binary = FirefoxBinary("C:\Program Files (x86)\MozillaFirefox\firefox.exe")
profile = FirefoxProfile("C:\Users\User\Documents\dxcwavid.Zydrius5")
driver = webdriver.Firefox(firefox_profile=profile, firefox_binary=binary)
driver.get("http://google.com")
To load an existing Firefox Profile through Selenium and Python you can use the following solution:
Code Block:
from selenium import webdriver
myprofile = webdriver.FirefoxProfile(r'C:\Users\AtechM_03\AppData\Roaming\Mozilla\Firefox\Profiles\moskcpdq.SeleniumTest')
driver = webdriver.Firefox(firefox_profile=myprofile, executable_path=r'C:\Utility\BrowserDrivers\geckodriver.exe')
driver.get('https://www.google.co.in')
print("Page Title is : %s" %driver.title)
driver.quit()
Console Output:
Page Title is : Google
References:
webdriver.FirefoxProfile(): Is it possible to use a profile without making a copy of it?
Creating Firefox profile and switching off the marionette

Unable to handle Chrome notifications in Python [duplicate]

How can Selenium Chrome WebDriver notifications be handled in Python?
Have tried to dismiss/accept alert and active element but seems notifications have to be treated other way. Also, all the Google search results are driving me to Java solution which I do not really need. I'm a newbie in Python.
Thanks in advance.
You can disable the browser notifications, using chrome options.
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
In December, 2021, using ChromeDriver Version: 96, the python code structure would look like below to handle the ChromeDriver/ Browser notification:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
# Creating Instance
option = Options()
# Working with the 'add_argument' Method to modify Driver Default Notification
option.add_argument('--disable-notifications')
# Passing Driver path alongside with Driver modified Options
browser = webdriver.Chrome(executable_path= your_chrome_driver_path, chrome_options= option)
# Do your stuff and quit your driver/ browser
browser.get('https://www.google.com')
browser.quit()
The answer above from Dec '16 didn't work for me in August 2020. Both Selenium and Chrome have changed, I believe.
I'm using the binary for Chrome 84, which is listed as the current version, even though there's a binary for Chrome 85 available from selenium.dev. I have to presume that's a beta since I have no other info on that.
I only have a partial answer so far, but I believe the following two lines are in the right direction. They're as far as I've gotten tonight. I have a test window that I've opened to Facebook and have the exact window shown in the Question. The code given in pythonjar's answer from Dec 30 '16 above produced error messages for me. These code lines worked without error, so I believe this is the right track.
>>> from selenium.webdriver import ChromeOptions
>>> chrome_options = ChromeOptions()
I'll update this tomorrow, if I get time to work on it.
Sorry for the partial answer. I hope to complete it soon. I hope this helps. If you get there first, please let me know.
Using Chrome Versão 85.0.4183.83 (Versão oficial) 64 bits and ChromeDriver 85.0.4183.83
Here is the code and it is working:
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications" : 2}
chrome_options.add_experimental_option("prefs",prefs)
driver = webdriver.Chrome(chrome_options=chrome_options)
driver.get("https://www.google.com/")
2020/08/27
Follow the below code for handling the notification settings with Python selenium
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
option = Options()
option.add_argument("--disable-infobars")
option.add_argument("start-maximized")
option.add_argument("--disable-extensions")
option.add_experimental_option("prefs",
{"profile.default_content_setting_values.notifications": 2
})
Note 1-to allow notification, 2- to block notification

Categories

Resources