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).
Related
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.
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.
Using selenium webdriver with Edge browser. Worked fine until last night/morning. Errors are:
selenium.common.exceptions.SessionNotCreatedException: Message: session not created: This version of MSEdgeDriver only supports MSEdge version 96
Current browser version is 98.whatever. It says the application was modified on 2/3 of this year, which I didn't consent to as far as I can remember.
Why did that catch? Did it automatically install an update without letting me know? Why would that be?
In any case, TLDR, how do I fix this?! and which does Selenium dislike: my edgeDriver, or Selenium being out of date? should I REVERT EdgeDriver by finding an older version (how?), or would it be best to update Selenium somehow?
I have been struggling to figure out why I keep getting errors trying to use selenium. I'm using a local install of anaconda3 on my /home/user unix drive at the company I work for. I already pip installed selenium, seemingly without issue, but when I try the following:
from selenium import webdriver
driver = webdriver.Firefox()
it fails with the following message:
WebDriverException: Message: Expected browser binary location, but unable to find binary in default location, no 'moz:firefoxOptions.binary' capability provided, and no binary flag set on the command line
I've tried downloading the most current chromedriver and trying with that, I've tried installing another gecko-driver, I've tried all kinds of things. But nothing is working. I'm happy to provide any amount of additional information, I just want to get this off the ground at some point...
Thank you!
from selenium import webdriver
path = r'C:\yourgeckodriverpath\geckodriver.exe'
driver = webdriver.Firefox(executable_path=path)
Alright, through a combination of the responses to this question, I have figured out what (I think) went wrong. I was using a linux anaconda install on my company's servers, which (I believe) meant my python had no access to a browser driver. The solution was sadly to install anaconda locally, manually download/unzip/install selenium and geckodriver, and then make sure I pass the whole "executable_path=path" parameter to the Firefox method. This didn't work for Chrome for some reason, which I'll assume has something to do with the unchangeable security specifications on my work machine. If any part of this doesn't sound right, feel free to chime in and shed more light on the issue. Thanks!
I've been working with the following code, trying to introduce myself to selenium. When it runs, the chrome browser opens, but the page is blank, with no source code a far as I can tell, and 'data;' in the address bar. Any information on why this is happening would be greatly appreciated.
from selenium import webdriver
browser = webdriver.Chrome(service_args = ['--ignore-ssl-errors=true', '--ssl-protocol=TLSv1'])
url = 'https://www.google.com/'
browser.get(url)
I have also tried it without the service_args and tried it specifying the driver path and both, but get the same result each time
The most possibility is your browser not compatible with the webdriver. Please confirm your browser version and webdriver version.
My chrome version is 60 and chromerdriver is chromedriver_2.30.exe
You can find compatible version from here
Update the chromedriver and Chrome Browser, sometime I also faced this issue.
I don't see any error as such in your code. Though the documentation for service_args is missing in the Selenium-Python API Docs as well as in the ChromeDriver Getting started Doc. But 0096850 clearly suggests service_args is implemented.
The service_args works well at my end. Hence I suspect there is a mismatch between Selenium version, chromedriver version and Chrome version we are using. First and foremost, we have to ensure that our Selenium version, chromedriver version and Chrome version are compatible. You can find the compatibility information on the Downloads page of ChromeDriver individually for each releases.
The Downloads page clearly mentions:
Latest Release: ChromeDriver 2.32 Supports Chrome v59-61
Additionally, you may be required to pass the argument executable_path to mention the absolute path of the chromedriver binary as follows:
Windows 8 based code:
from selenium import webdriver
browser = webdriver.Chrome(executable_path=r'C:\Utility\BrowserDrivers\chromedriver.exe', service_args = ['--ignore-ssl-errors=true', '--ssl-protocol=TLSv1'])
url = 'https://www.google.com/'
browser.get(url)
I've met the same problem,but I solved it by updating my webdriver
Update your webdriver of chrome ,here is the link https://sites.google.com/a/chromium.org/chromedriver/downloads
If you're using Codeception, start the test with :
$I->amOnPage('/');
simply add this argument to selenium options (google how add options on solenium python to how to add options argument)
options.add_argument("--remote-debugging-port=9225")