Hello, how do i solve this driver python error? - python

from selenium import webdriver
import time
import random
numara = input("numarayi yaz ")
mesajSayisi = int(input("kac mesaj "))
sayi = random.randint(10000, 1000000)
sayi = str(sayi)
id = 'asdasd' + sayi
driver = webdriver.Chrome("D:\\Users\mutam\Desktop\sms_metin2\chromedriver.exe")
url = "https://www.hisarmt2.com/kayit-ol"
driver.Chrome.get(url)
when i run this code i get this error, anyone can help please?
driver = webdriver.Chrome("D:\\Users\mutam\Desktop\sms_metin2\chromedriver.exe")
Traceback (most recent call last):
File "D:\Users\mutam\Desktop\sms_metin2\main.py", line 9, in <module>
driver = webdriver.Chrome("D:\\Users\mutam\Desktop\sms_metin2\chromedriver.exe")

I'm not sure what your exact issue is... In the newer versions of Selenium the driver path is depreciated. Try installing webdriver_manager and using this below.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import Select
from webdriver_manager.chrome import ChromeDriverManager #install webdriver_manager
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(ChromeDriverManager().install())
driver.maximize_window()
driver.get('website')

Related

AttributeError: 'Options' object has no attribute 'add_experimental_option'

hi guys I hope that you are having a great time.
so I'm having this problem when I'm tring to execute this script.
import selenium.webdriver as webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
from selenium.webdriver.chrome.options import Options
url = "https://www.google.com/"
chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:9222")
#Change chrome driver path accordingly
driver = webdriver.Chrome(
executable_path = r"C: \drivers\chromedriver.exe", chrome_options =chrome_options)
print (driver.title)
the results in cmd:
Traceback (most recent call last):
File "C:\Users\modaw\Desktop\firefox elo\hi.py", line 12, in <module>
opts.add_experimental_option('debuggerAddress', 'localhost:9222')
AttributeError: 'Options' object has no attribute 'add_experimental_option'
if you have the same problem try using this string with code
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
opt=Options()
opt.add_experimental_option("debuggerAddress","localhost:8989")
driver = webdriver.Chrome(executable_path="chromedriver.exe",chrome_options=opt)
driver.get("http://google.com")
You need to change the third line to from selenium.webdriver.chrome.options import Options instead of from selenium.webdriver.chrome.options import options since the Options class is uppercase. Otherwise Python will not import it successfully.
Python names are case-sensitive.
Chrome WebDriver Options Methods

Selenium webdriver.Firefox() not working on windows

I'm trying to webscrape images from the web using selenium. On Linux there do not seem to be any problems however when running on windows the program seems to exit on line 18.
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.firefox.service import Service
from webdriver_manager.firefox import GeckoDriverManager
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.by import By
import os
import requests
import base64
def webscrape(query, max_count, q):
options = Options()
options.add_argument('-headless')
# Add a GH_token to the environment so there are no limitations on the number of requests.
os.environ['GH_TOKEN'] = "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"
gecko = GeckoDriverManager().install()
driver = webdriver.Firefox(service=Service(gecko), options=options)
driver.get("https://www.google.com/search?q=" + query + "&tbm=isch")
print("test")
the test print doesn't happen. But all print statements before the driver.get call do.

I tried using webdriver manager but i keep getting this error

I tried selenium automation with webdriver but I keep getting errors. Please help me fix the problem
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from time import sleep
browser = webdriver.Chrome("chromedriver.exe")
browser.get("https://python.org")
the Error I received:
File "C:\Users\LUCKY-PC\OneDrive\Desktop\Python\automation\selenium_test.py", line 2, in <module>
from webdriver_manager.chrome import ChromeDriverManager
File "C:\Users\LUCKY-PC\anaconda3\lib\site-packages\webdriver_manager\chrome.py", line 4, in <module>
from webdriver_manager import utils
File "C:\Users\LUCKY-PC\anaconda3\lib\site-packages\webdriver_manager\utils.py", line 8, in <module>
import requests
File "C:\Users\LUCKY-PC\anaconda3\lib\site-packages\requests\__init__.py", line 95, in <module>
from urllib3.contrib import pyopenssl
File "C:\Users\LUCKY-PC\anaconda3\lib\site-packages\urllib3\contrib\pyopenssl.py", line 109, in <module>
orig_util_SSLContext = util.ssl_.SSLContext
AttributeError: module 'urllib3.util' has no attribute 'ssl_'
Try with ChromeDriverManager().install():
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
browser = webdriver.Chrome(ChromeDriverManager().install())
browser.get("https://python.org")
It's better if you download the chrome driver and then provide the chrome driver path to code.
Go to your chrome browser and type chrome://settings/help. From here you can find your chrome version.
Then go to https://chromedriver.chromium.org/downloads to download a chrome driver that matches your chrome version.
Now give the path to of that driver in the code below.
import os
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
class Driver_Class(webdriver.Chrome):
def __init__(self, driver_path, teardown=False):
self.driver_path = driver_path
self.options = Options()
self.options.headless = False
self.driver = webdriver.Chrome(executable_path=self.driver_path,options=self.options)
self.options.add_argument('--ignore-certificate-errors')
self.options.add_argument('--ignore-ssl-errors')
self.teardown = teardown
os.environ['PATH'] += self.driver_path
self.driver.implicitly_wait(30)
self.driver.maximize_window()
def get_driver(self):
return self.driver
driverObj = Driver_Class("chrome_driver_path")
driver = driverObj.get_driver()
Now you can use this driver for the rest of your program.

Why does setting Edge profile results in an error in Selenium Python

I am trying to run Whatsapp web without scanning QR code every time, thus I passed a profile of Edge so that it automatically detects the previous session without asking to scan it again.
Here's my code:
import cv2
from selenium import webdriver
from selenium.webdriver.common import keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
import threading as thread
from selenium.webdriver.firefox.webdriver import WebDriver
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
import time
from msedge.selenium_tools import EdgeOptions
from msedge.selenium_tools import Edge
option = EdgeOptions()
option.use_chromium = True
option.add_argument("--headless")
option.add_argument('user-data-dir= C://Users//USERNAME//AppData//Local//Microsoft//Edge SxS//User Data')
driver = webdriver.Edge(executable_path="J://edgedriver_win64//msedgedriver.exe",options = option)
driver.get('https://web.whatsapp.com')
wait = WebDriverWait(driver, 60)
But I am getting an error:
File "h:\Huzaifa\Python\Project\OpenCV\Spam1.py", line 19, in
driver = webdriver.Edge(executable_path="J://edgedriver_win64//msedgedriver.exe",options
= option) TypeError: init() got an unexpected keyword argument 'options'
I tried running it headless and things but it just won't work.
Any help would be massively appreciated. Thanks!
it could be a selenium version issue. The version of selenium you are using do not support the options argument. You can see the documentation for Firefox object that you're using by starting a Python console and:
from selenium.webdriver import Firefox
help(Firefox)

How do I import the url_page function from my nav.py file into mine.py?

These are my files:
./mine.py
./nav.py
I'm trying to import the url_page function from the nav.py file into mine.py.
nav.py
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.common.keys import Keys
import time
# --- ROTINAS INICIAIS ---
options = Options()
options.add_argument("--headless")
driver = webdriver.Firefox(firefox_options=options, executable_path="./geckodriver")
print("Firefox Headless Browser Invoked")
driver.get("https://www.google.com.br/")
def url_page(code_share):
elem = driver.find_element_by_name("q")
code_share = code_share + " código"
elem.send_keys(code_share + Keys.ENTER);
time.sleep(2)
return print(driver.current_url)
mine.py
import json
import time
from bs4 import BeautifulSoup
from nav.py import url_page
url_page("AMBEV S.A.")
This is the error message:
Firefox Headless Browser Invoked
Traceback (most recent call last):
File "mine.py", line 4, in <module>
from nav.py import url_page
ModuleNotFoundError: No module named "nav.py"; "nav" is not a package
in mine.py
add import nav and use nav.url_page()
remove from nav.py import url_page from your code

Categories

Resources