webdrivermanager TypeError - python

Trying to use webdrivermanager for selenium
I am using python version 2.7.13.
I am running a backing setup for setting up webdriver as explained in the docs.
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
As far as I know it says that this package does work for python 2. But I get the following TypeError:
TypeError: super() takes at least 1 argument (0 given)
I am thinking this is the difference between Python 2 and 3, but I have seen people running this package on Python 2...
I have tried:
driver = webdriver.Chrome(ChromeDriverManager(ChromeDriverManager, self).install())
But it says self is not defined?!

Webdriver manager supports the only python version >=3.6

Related

Selenium Webdriver Manager Doesn't Write in the Console Like Expected

https://www.youtube.com/watch?v=Z3M2GBu8t_k&list=PLL34mf651faPOf5PE5YjYgTRITzVzzvMz&index=11
I've been following this youtube tutorial as I set up Selenium. Once he downloads the webdriver manager and runs his code, he gets a lot of [WDM}... output, but I don't get that.
DeprecationWarning: executable_path has been deprecated selenium python
This link also shows the output that I'm not getting, so I think I'm doing something wrong.
Here's my code:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.get("https://www.rcvacademy.com")
driver.maximize_window()
print(driver.title)
driver.close()
And this is my output:
"C:\Program Files\Python311\python.exe" C:\python-selenium\PythonSeleniumProject1\LearningSelenium\AutomationTestv2.py
Home El - RCV Academy
Process finished with exit code 0
What am I doing wrong?
I'm not exactly sure what to try
Those are the information used to appear in the console if you use the older version of webdriver-manager.
I installed webdriver_manager v3.3.0 as you mentioned in the youtube video, I got the below log in the console:
In the latest versions, you won't get that.
You can check by uninstalling the newer version and installing the older version in Pycharm. Go to Python Packages > search and select webdriver-manager > in the right side pane > select delete package. Then you can install the older version from the dropdown and verify.
You just trying to print the title of the page only then what you more expected from the webdriver.
if you want to look over the whole page content, then you can try
print(driver.page_source)
As per webdriver-manager website - with the latest versions, you need to setup the logging process. You can enable logging by running this script:
Setup Logging
import logging
from webdriver_manager.core.logger import set_logger
logger = logging.getLogger("custom_logger")
logger.setLevel(logging.DEBUG)
logger.addHandler(logging.StreamHandler())
logger.addHandler(logging.FileHandler("custom.log"))
set_logger(logger)
You should then be able to carry on as per normal (provided you are using Chrome, and Selenium v4):
Here is the suggested code (which is slightly different to yours):
Code:
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))
driver.get("https://www.rcvacademy.com")
driver.maximize_window()
print(driver.title)
driver.close()
Output:
====== WebDriver manager ======
Get LATEST chromedriver version for google-chrome 109.0.5414
Driver [C:\Users\scottc\.wdm\drivers\chromedriver\win32\109.0.5414\chromedriver.exe] found in cache
Home El - RCV Academy
Note:
The amount of information logged will depend on whether or not you currently have the latest driver installed. If you already have the latest driver installed, then you should expect to see minimal lines (as per the output above). However, if you are missing the current driver on your system, you can expect to see a more verbose output.
Logging is optional, and not necessary for successful website analysis.

Problems with Chrome webdriver

Getting started with using Chrome webdrivers and selenium. When I execute the code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
driver = webdriver.Chrome(executable_path = \
r"C:\Users\payto\Downloads\chromedriver_win32.zip\chromedriver.exe")
I keep getting this error:
WebDriverException: 'chromedriver.exe' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home
I've looked up how to solve it, but anything I see says to install a webdriver...which I've already done. My Chrome version is 107 and that's the one I downloaded, so it should be working but it's not. Any tips?
You can use webdriver_manager instead of constantly setting executable_path and chromedriver yourself.
For chrome driver:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
it will automatically download the appropriate chromedriver. if it's already loaded, it finds it in the cache and uses it directly.
Solution
You can get rid of all driver versions issues by using ChromeDriverManager
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()))
driver.maximize_window()
driver.get("https://www.google.com")
OR Fixing the issue in your existing code like ..
Downloading a specific version of ChromeDriver you can use the following code block:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
s = Service('C:/Users/hp/Downloads/chromedriver/chromedriver.exe')
driver = webdriver.Chrome(service=s)
You can find more discussion here, hope this will help you.
You actually have to install the Chrome Browser on you machine.
Go to https://www.google.com/intl/en_en/chrome/, download and install it.
It is needed to run Selenium/ Chrome.

'WebDriver' object has no attribute 'find_element_by_link_text' - Selenium script suddenly stopped working

This is a weird issue I have ran into and I can't find any solution for this across the internet. I was using selenium in google colab to scrape a website and my code was working completely fine. I woke up the next day and ran the code again without changing a single line and don't know how/why my code starting giving me this error, AttributeError: 'WebDriver' object has no attribute 'find_element_by_link_text'. Same for find_element_by_class_name and id etc. I then rechecked a previously working script just to confirm and that gave me the same error too. I am confused about what happened suddenly and the scripts started giving me these errors.
How do I solve this? What am I doing wrong here?
!pip install selenium
!apt-get update
!apt install chromium-chromedriver
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--disable-dev-shm-usage')
driver = webdriver.Chrome('chromedriver',options=chrome_options)
driver.get("https://petrowiki.spe.org/PetroWiki")
driver.title #this line is returning the correct title value, code is able to access the url
peh = driver.find_element_by_link_text('Pet. Eng. Handbook')
peh.click()
Selenium just removed that method in version 4.3.0. See the CHANGES: https://github.com/SeleniumHQ/selenium/blob/a4995e2c096239b42c373f26498a6c9bb4f2b3e7/py/CHANGES
Selenium 4.3.0
* Deprecated find_element_by_* and find_elements_by_* are now removed (#10712)
* Deprecated Opera support has been removed (#10630)
* Fully upgraded from python 2x to 3.7 syntax and features (#10647)
* Added a devtools version fallback mechanism to look for an older version when mismatch occurs (#10749)
* Better support for co-operative multi inheritance by utilising super() throughout
* Improved type hints throughout
You now need to use:
driver.find_element("link text", "Pet. Eng. Handbook")
For improved reliability, you should consider using WebDriverWait in combination with element_to_be_clickable.

Python Webdriver Manager: Linux Problem on Webdriver Manager for Python

Linux Problem on Webdriver Manager Python
Details:
System - Manjaro Linux
IDE: Visueal Studio Code
Currently, I used the Webdriver Manager tutorial in Python to make my work easier. But IE and Edge are giving me problems.
The Integration:
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(EdgeChromiumDriverManager().install())
Chromium,Chrome and Firefox to some extent, but there I found a workaround that works thanks to Stackoverflow.
When running Edge on Manjaro Linux I get the following error:
ValueError: There is no such driver by url https://msedgedriver.azureedge.net/91.0.864.70/edgedriver_linux64.zip
[WDM] - ====== WebDriver manager ======
[WDM] - There is no [linux64] edgedriver for browser in cache
[WDM] - Trying to download new driver from https://msedgedriver.azureedge.net/91.0.864.70/edgedriver_linux64.zip
So the question is, is there currently no webdriver for Linux that allows to test IE/Edge on Linux as well?
Is there a workaround?
Version you try to download - missing on the server.
Try change url for download. You can check all verions here.
For example you can install valid driver ( other version ) from this url:
https://msedgewebdriverstorage.blob.core.windows.net/edgewebdriver/92.0.878.0/edgedriver_linux64.zip
Or change code to (specify neeeded and valid version to installation):
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(EdgeChromiumDriverManager(version="92.0.878.0").install())
Try webdriver-manager>=3.5.1.
Selecting EdgeDriver on Linux and executable permissions were fixed in 3.5.1.
Released to pypi today https://pypi.org/project/webdriver-manager/3.5.1/

How to use selenium capabilities for Firefox in splinter?

I'm using python splinter which is built on selenium, i want to use another webdriver for firefox as starting from version 47 firefox changed the webdriver as per below link
https://developer.mozilla.org/en-US/docs/Mozilla/QA/Marionette/WebDriver
splinter docs says you can pass capabilities argument to use selenium capabilities
from splinter import Browser
browser = Browser(‘firefox’, capabilities={‘acceptSslCerts’: True})
http://splinter.readthedocs.io/en/master/drivers/firefox.html#how-to-use-selenium-capabilities-for-firefox
but when using testing i got the error
TypeError: init() got an unexpected keyword argument 'capabilities'
also class splinter.driver.webdriver.firefox.WebDriver doesn't contain capabilites, although in splinter doc it contains it, i have the latest version what am i missing?!
__init__(self, profile=None, extensions=None, user_agent=None, profile_preferences=None, fullscreen=False, wait_time=2)
You are looking at the documentation generated for the master branch of the splinter project.
For capabilities to work, you need to uninstall splinter and install it directly from github:
$ pip uninstall splinter
$ pip install git+https://github.com/cobrateam/splinter#master
(worked for me).

Categories