I tried code below in TEST.py:32
print("ChromeDriverManager().install() :", ChromeDriverManager().install())
[WDM] - ====== WebDriver manager ======
2022-07-05 19:49:04,445 INFO ====== WebDriver manager ======
Traceback (most recent call last):
File "d:\Python\PYTHONWORKSPACE\repo\Auto-booking-master\src\TEST.py", line 32, in <module>
print("ChromeDriverManager().install() :", ChromeDriverManager().install())
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\chrome.py", line 38, in install
driver_path = self._get_driver_path(self.driver)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\core\manager.py", line 29, in _get_driver_path
binary_path = self.driver_cache.find_driver(driver)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\core\driver_cache.py", line 95, in find_driver
driver_version = driver.get_version()
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\core\driver.py", line 43, in get_version
self.get_latest_release_version()
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\drivers\chrome.py", line 37, in get_latest_release_version
self.browser_version = get_browser_version_from_os(self.chrome_type)
File "C:\Users\user\AppData\Local\Programs\Python\Python310\lib\site-packages\webdriver_manager\core\utils.py", line 152, in get_browser_version_from_os
cmd_mapping = {
KeyError: 'google-chrome'
Please help me.
Install webdriver-manager:
pip install webdriver-manager, pip install selenium
And then:
# selenium 4
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
option = webdriver.ChromeOptions()
option.add_argument("start-maximized")
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=option)
driver.get('https://www.google.com/')
WebDriverManager
Related
my goal is to run a python script that uses Selenium to manipulate the chrome browser, directly with Pydroid 3 app on my android smartphone (without a pc connection).
I followed the instructions at the link https://chromedriver.chromium.org/getting-started/getting-started---android to download the appropriate webdriver and set it correctly for Android.
In detail the version of Chrome on my Smartphone (Samsung S10) is 108.0.5359.128 therefore, following what is indicated here:
https://chromedriver.chromium.org/downloads#h.p_ID_32
I downloaded webdriver "chromedriver_linux64.zip" present at the following link:
https://chromedriver.storage.googleapis.com/index.html?path=108.0.5359.71/
But following this example
https://chromedriver.chromium.org/getting-started/getting-started---android#h.p_ID_390 and running the following Python3 script:
from selenium import webdriver
path_to_chromedriver = os.path.dirname(__file__) + '/chromedriver'
print('path_to_chromedriver: ', path_to_chromedriver)
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome(path_to_chromedriver, 0, options=options)
driver.get('https://google.com')
driver.quit()
or this one:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
path_to_chromedriver = os.path.dirname(__file__) + '/chromedriver'
print('path_to_chromedriver: ', path_to_chromedriver)
service = Service(path_to_chromedriver)
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver = webdriver.Chrome(service=service, options=options)
driver.get('https://google.com')
I get this error:
path_to_chromedriver: /storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/chromedriver
Traceback (most recent call last):
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 31, in <module>
start(fakepyfile,mainpyfile)
File "/data/user/0/ru.iiec.pydroid3/files/accomp_files/iiec_run/iiec_run.py", line 30, in start
exec(open(mainpyfile).read(), __main__.__dict__)
File "<string>", line 124, in <module>
File "/storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/justwatchScraper.py", line 168, in start
scrolledGenrePage = scrollGenrePageToTheEnd(genrePageURL)
File "/storage/emulated/0/Download/ke-ce-verimme-justwatch-scraper/ke-ce-verimme-justwatch-scraper/scrapers/justwatchScraper.py", line 47, in scrollGenrePageToTheEnd
driver = webdriver.Chrome(service=service, options=options)
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
super().__init__(
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
self.service.start()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 106, in start
self.assert_process_still_running()
File "/data/user/0/ru.iiec.pydroid3/files/aarch64-linux-android/lib/python3.9/site-packages/selenium/webdriver/common/service.py", line 117, in assert_process_still_running
return_code = self.process.poll()
AttributeError: 'Service' object has no attribute 'process'
[Program finished]
Can anyone help me or suggest a workaround?
I am using SELENIUM IN MY ANDROID PHONE USING TERMUX
HERE IS MY CODE
`
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_experimental_option('androidPackage', 'com.android.chrome')
driver=webdriver.Chrome('./chromedriver', options=options)
driver.get('https://google.com')
driver.quit()`
And THIS IS THE ERROR I M GETTING
/storage/emulated/0/Download/Instagram-Bot-Scrape-DM-Users-main/Instagram-Bot-Scrape-DM-Users-main/hh.py:5: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
driver = webdriver.Chrome('./chromedriver', options=options)
Traceback (most recent call last):
File "/storage/emulated/0/Download/Instagram-Bot-Scrape-DM-Users-main/Instagram-Bot-Scrape-DM-Users-main/hh.py", line 5, in <module>
driver = webdriver.Chrome('./chromedriver', options=options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
super().__init__(
File "/data/data/com.termux/files/usr/lib/python3.11/site-packages/selenium/webdriver/chromium/webdriver.py", line 103, in __init__
New to Python Selenium.
I am trying to create an script to login to my home router and press the button restart.
Running to error, when trying to login to the router, can some on guide on my mistake here.
below is the code and also attaching the .screenshot
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
driver_service = Service(executable_path="C:\Program Files (x86)\chromedriver.exe")
driver = webdriver.Chrome(service=driver_service)
PASSWORD = 'testtes'
login_page = 'http://192.168.2.1/login.html'
driver.get(login_page)
driver.find_element_by_xpath("//input[#placeholder='Password']").send_keys(PASSWORD)
Below is the error I am getting.
Traceback (most recent call last):
File "C:\Users\admin\Desktop\pyhton\index.py", line 14, in
driver.find_element_by_xpath("//input[#placeholder='Password']").send_keys(PASSWORD)
AttributeError: 'WebDriver' object has no attribute 'find_element_by_xpath'
getting this error now.
Traceback (most recent call last):
File "C:\Users\admin\Desktop\pyhton\index.py", line 13, in
driver.find_element(By.XPATH, "//input[#placeholder='Password']").send_keys(PASSWORD)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 856, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[#placeholder='Password']"}
Probably you are using Selenium 4. if so, find_element_by_xpath and all the others find_element_by_* methods are not supported by Selenium 4, you have to use the new syntax and add an essential import, as following:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
driver_service = Service(executable_path="C:\Program Files (x86)\chromedriver.exe")
driver = webdriver.Chrome(service=driver_service)
PASSWORD = 'testtes'
login_page = 'http://192.168.2.1/login.html'
driver.get(login_page)
driver.find_element(By.XPATH, "//input[#placeholder='Password']").send_keys(PASSWORD)
Try this:
from selenium.webdriver.common.by import By
driver.find_element(By.XPATH, "//input[#placeholder='Password']").send_keys(PASSWORD)
I'm trying to run a simple python script that open firefox and search some info on https://biblioteca.aneel.gov.br/.
On my computer the script works, but when i try to run on heroku, it always crashes. I tried all tutorials that I could find, but I don't know what more to do.
I did:
I put as 'Buildpacks' on heroku: https://github.com/pyronlaboratory/heroku-integrated-firefox-geckodriver
In 'Config Vars' on heroku:
FIREFOX_BIN = /app/vendor/firefox/firefox
GECKODRIVER_PATH = /app/vendor/geckodriver/geckodriver
LD_LIBRARY_PATH = /usr/local/lib:/usr/lib:/lib:/app/vendor
PATH = /usr/local/bin:/usr/bin:/bin:/app/vendor/
Adjuste code on heroku:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
from bs4 import BeautifulSoup
import re
import yagmail
import time
import os
options = webdriver.FirefoxOptions()
# enable trace level for debugging
options.log.level = "trace"
options.add_argument("-remote-debugging-port=9224")
options.add_argument("-headless")
options.add_argument("-disable-gpu")
options.add_argument("-no-sandbox")
binary = FirefoxBinary(os.environ.get('FIREFOX_BIN'))
rea_inicial='teste'
while True:
driver = webdriver.Firefox(firefox_binary=binary, executable_path=os.environ.get('GECKODRIVER_PATH'), options=options)
#driver.maximize_window()
driver.get("https://biblioteca.aneel.gov.br/Busca/Avancada")
print('entrando no site...')
#time.sleep(5)
# Busca por legislacoo
driver.find_element(By.XPATH, '/html/body/main/div/div/div[2]/div/div/button[2]').click()
wait = WebDriverWait(driver, 30)
print('chegou ate aqui')
Then, the error after deploy on heroku:
2021-11-05T17:40:55.035807+00:00 app[worker.1]: code.py:24: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
2021-11-05T17:40:55.035820+00:00 app[worker.1]: driver = webdriver.Firefox(firefox_binary=binary, executable_path=os.environ.get('GECKODRIVER_PATH'), options=options)
2021-11-05T17:40:55.035825+00:00 app[worker.1]: code.py:24: DeprecationWarning: firefox_binary has been deprecated, please pass in a Service object
2021-11-05T17:40:55.035825+00:00 app[worker.1]: driver = webdriver.Firefox(firefox_binary=binary, executable_path=os.environ.get('GECKODRIVER_PATH'), options=options)
2021-11-05T17:40:55.540760+00:00 app[worker.1]: Traceback (most recent call last):
2021-11-05T17:40:55.540774+00:00 app[worker.1]: File "code.py", line 24, in <module>
2021-11-05T17:40:55.540947+00:00 app[worker.1]: driver = webdriver.Firefox(firefox_binary=binary, executable_path=os.environ.get('GECKODRIVER_PATH'), options=options)
2021-11-05T17:40:55.540949+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/selenium/webdriver/firefox/webdriver.py", line 175, in __init__
2021-11-05T17:40:55.541113+00:00 app[worker.1]: self.service.start()
2021-11-05T17:40:55.541123+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 101, in start
2021-11-05T17:40:55.541249+00:00 app[worker.1]: self.assert_process_still_running()
2021-11-05T17:40:55.541250+00:00 app[worker.1]: File "/app/.heroku/python/lib/python3.8/site-packages/selenium/webdriver/common/service.py", line 113, in assert_process_still_running
2021-11-05T17:40:55.541359+00:00 app[worker.1]: raise WebDriverException(
2021-11-05T17:40:55.541409+00:00 app[worker.1]: selenium.common.exceptions.WebDriverException: Message: Service /app/vendor/geckodriver/geckodriver unexpectedly exited. Status code was: 64
Can anyone helps me how to solve it ?
The following arguments:
-no-sandbox
-disable-gpu
perhaps are applicable to ChromeDriver / google-chrome combo but Not Applicable to GeckoDriver / firefox combo.
Remove the arguments and re-execute.
Good morning,
I was trying to access a web application and collect browser console logs (Web Developer -> Web Console).
I am getting an error
File "test1.py", line 28, in <module>
logs = driver.get_log('browser')
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 1262, in get_log
return self.execute(Command.GET_LOG, {'type': log_type})['value']
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 208, in check_response
raise exception_class(value)
selenium.common.exceptions.WebDriverException: Message: HTTP method not allowed
my code is like this.
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
import time
from selenium.webdriver.support.ui import WebDriverWait
binary = r'C:\Program Files\Mozilla Firefox\firefox.exe'
options = Options()
options.binary = binary
cap = DesiredCapabilities().FIREFOX
cap["marionette"] = True
cap['loggingPrefs'] = {'driver': 'ALL'}
driver = webdriver.Firefox(firefox_options=options, capabilities=cap, executable_path="C:\Python\geckodriver.exe")
driver.get('https://facebook.com')
time.sleep(2) # time for page to load
logs = driver.get_log('browser')
messages = map(lambda l: l['message'], logs)
has_console_logs = any(map(lambda m: m.find('console log') >= 0, messages))
print('Success' if has_console_logs else 'Failure')
driver.quit()