'WebDriver' object is not callable - python

I am trying to call webdriver from another but its showing me typeError with webdriver is not callable
fileName: "call_folder1"
import sys
sys.path.insert(1,"/Users/akru/Desktop/AKRU-Automation/automation-scripts/Staging/test_folder1/")
import Login_yopmail
obj1=Login_yopmail.setUpDriver()
obj1.initiate_driver()
driver=obj1.driver()
class login_yopmail:
def access_url(self):
url="https://avaxdev.akru.co"
def entre_email():
print("Login yopmail")
pass
here is file containing webriver
#import unittest
from selenium import webdriver
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service as ChromeService
class setUpDriver:
def initiate_driver(self):
WINDOW_SIZE = "1920,1080"
chrome_options = Options()
#chrome_options.add_argument("--headless")
chrome_options.add_argument("--disable-gpu")
chrome_options.add_argument("--disable-popup-blocking")
chrome_options.add_argument("--window-size=%s" % WINDOW_SIZE)
chrome_options.add_argument('--no-sandbox')
chrome_options.add_argument('--start-maximized')
chrome_options.add_argument('--disable-setuid-sandbox')
service = ChromeService(executable_path=ChromeDriverManager().install())
self.driver = webdriver.Chrome(service=service , options=chrome_options)
driver=self.driver
return driver
I am trying to call webdriver initiated in another python filer from another directory

Related

'NoneType' object has no attribute 'click'. Why i am getting this error

Why i am unable to use click function inside my class
# from selenium import webdriver
# from selenium.webdriver.chrome.options import Options
# from selenium.webdriver.chrome.service import Service
# from webdriver_manager.chrome import ChromeDriverManager
#
# options = Options()
# options.add_argument('--headless')
# options.add_argument('--no-sandbox')
# options.add_argument('--disable-dev-shm-usage')
# driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
#
# driver.get("https://python.org")
# print(driver.title)
####
import time
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import NoSuchWindowException
from selenium.common.exceptions import NoAlertPresentException
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager
import RFOS
options = Options()
# options.add_argument('--headless')
# options.add_argument('--no-sandbox')
options.add_argument('--disable-dev-shm-usage')
import pandas as pd
from datetime import datetime
#driver = RFOS.OpenBrowser('chrome')
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
class SetWindow():
def test(self):
url = RFOS.fetchDataFromPropertiesFile("Credentials.properties","Login", "url_ChatGpt")
driver.get(url)
driver.maximize_window()
time.sleep(60)
driver.find_element_by_xpath("//*[#id='grouped-demo']").click()
#search = driver.find_element(by=By.NAME, value="q")
#search.send_keys("Hey, Tecadmin")
#search.send_keys(Keys.RETURN)
ChatGpt = SetWindow()
ChatGpt.test()
time.sleep(123)
driver.close()
I wanted to click on search bar of https://www.futurepedia.io/
Unidentified error. Whenever i want to perform click function on searchbar of any website by using this code it throws this kind of error.
enter image description here: error
The code
driver.find_element_by_xpath("//*[#id='grouped-demo']")
appears to return None. You're then attempting to call .click() on it, which fails.
You just need to add some handling for the case it returns None. Something like:
element = driver.find_element_by_xpath("//*[#id='grouped-demo']")
if element is None:
# Handle None case
...
else:
element.click()

Selenium google crashes when running tests

from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(service=s)
driver.maximize_window()
driver.get('https://www.google.com')
driver.find_element(By.NAME, 'q').send_keys('Hello world' + Keys.ENTER)`
Help me pls,who faced such problem? There is a solution?
The browser starts and after a couple of seconds it closes, although I did not give the command to close. What's wrong?
Try using the detach option when initializing the chromedriver. As following:
from selenium import webdriver
from selenium.webdriver import Keys
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_experimental_option("detach", True)
chrome_options.add_argument("start-maximized")
s = Service(ChromeDriverManager().install())
driver = webdriver.Chrome(options=chrome_options, service=s)

TypeError: EnumMeta.__call__() missing 1 required positional argument: 'value'

I'm looking to setup a webdriver in a script as a headless. I'm able to run it as a non headless way but when i'm creating an instance of the Option() it says me missing 1 required positional argument: 'value'
chrome_options = Options()
Here's a replication of the issue I'm having on the project.
from selenium import webdriver
from webbrowser import Chrome
from ssl import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class PythonOrg():
def Setup(self):
self.chrome_options = Options()
self.chrome_options.add_argument("--headless")
# self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) #not a headless
self.driver = webdriver.Chrome(options=chrome_options)
def GetLink(self):
driver = self.driver
driver.get('https://www.python.org')
print(driver.title)
driver.close()
inst = PythonOrg()
inst.Setup()
inst.GetLink()
Note: I'm new to Python!
You imported a wrong import.
Instead of
from ssl import Options
It should be
from selenium.webdriver.chrome.options import Options
for chrome_options add self.
and use from selenium.webdriver.chrome.options import Options not from ssl import Options
from selenium import webdriver
from webbrowser import Chrome
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class PythonOrg():
def Setup(self):
self.chrome_options = Options()
self.chrome_options.add_argument("--headless")
# self.driver = webdriver.Chrome(service=Service(ChromeDriverManager().install())) #not a headless
self.driver = webdriver.Chrome(options=self.chrome_options)
def GetLink(self):
driver = self.driver
driver.get('https://www.python.org')
print(driver.title)
driver.close()
inst = PythonOrg()
inst.Setup()
inst.GetLink()

Accept/bypass cookies with Selenium

I'm trying to get a screen shot from of a website from an url
however how can I accept the cookies before the screen shot ?
If you have any idea or clue I will appreciate.
Here is a following picture example of cookies :
Here is my code:
import time
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
start = time.time()
browser = webdriver.Chrome(ChromeDriverManager().install())
browser.get("https://candidat.pole-emploi.fr/offres/recherche/detail/136LNXS/")
browser.save_screenshot('screenshot1.png')
browser.quit()
end = time.time()
print("tempo =","\t",end - start)
You have to click on accept-button to accept cookie
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
import time
# selenium 4
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
#from selenium.webdriver.chrome.options import Options
options = webdriver.ChromeOptions()
options.add_argument("start-maximized")
options.add_argument("--no-sandbox")
options.add_argument("--disable-gpu")
options.add_argument("--disable-extensions")
#chrome to stay open
options.add_experimental_option("detach", True)
driver = webdriver.Chrome(service=Service(ChromeDriverManager().install()),options=options)
driver.get('https://candidat.pole-emploi.fr/offres/recherche/detail/136LNXS')
WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, '//*[#id="footer_tc_privacy_button_2"]'))).click()

Selenium closes browser right after opening

I am trying to open Brave using Selenium (in Python). It actually opens but then immediately closes with the following errors appearing in the console:
[23340:9252:1107/063438.209:ERROR:os_crypt_win.cc(93)] Failed to
decrypt: The parameter is incorrect. (0x57)
[23340:9252:1107/063438.210:ERROR:brave_sync_prefs.cc(114)] Decrypt
sync seed failure
DevTools listening on
ws://127.0.0.1:53809/devtools/browser/ecce3b0e-2884-4173-bdab-2215a3d7f507
[23340:9252:1107/063438.480:ERROR:CONSOLE(1)] "[Shields]: Can't
request shields panel data for tabId: 2. Error: No tab url
specified", source:
chrome-extension://mnojpmjdmbbfmejpflffifhffcmidifd/out/brave_extension_background.bundle.js
(1)
I've done some searching but couldn't really find anything helpful.
Here is my code:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
service = Service("C:/Auxiliary/chromedriver_win32/chromedriver.exe")
options.binary_location = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
self.driver = webdriver.Chrome(service=service, options=options)
self.driver.get("https://google.com")
Selen()
I'm using Windows 11.
Firstly, do you have chrome installed, and secondly, does it work if you do this?
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
path = "C:/Auxiliary/chromedriver_win32/chromedriver.exe"
self.driver = webdriver.Chrome(executable_path=path, options=options)
self.driver.get("https://google.com")
time.sleep(20)
driver.close()
instance = Selen()
If it does work, try this to get it to work with brave,
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from webdriver_manager.chrome import ChromeDriverManager
class Selen:
def __init__(self):
options = Options()
options.binary_location = "C:/Program Files/BraveSoftware/Brave-Browser/Application/brave.exe"
path = "C:/Auxiliary/chromedriver_win32/chromedriver.exe"
self.driver = webdriver.Chrome(executable_path=path, options=options)
self.driver.get("https://google.com")
time.sleep(20)
driver.close()
instance = Selen()

Categories

Resources