I have a problem the browser manager library does not work Webdriver Manager for Python. The following error appears, tell me how to fix it.
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from webdriver_manager.firefox import GeckoDriverManager
class MainPage:
driver = webdriver.Chrome(GeckoDriverManager().install())
def __init__(self, link):
self.link = link
def connect(self):
with self.driver as dr:
dr.get(self.link)
if __name__ == '__main__':
m = MainPage('https://ru.wikipedia.org/')
ValueError:
Could not get version for Chrome with this command: reg query
"HKEY_CURRENT_USER\Software\Google\Chrome\BLBeacon" /v version
GeckoDriverManager - this should be for FireFox.
Why are you mixing things ?
Chrome(GeckoDriverManager().install())
This is not right way.
Install webdriver manager like this :
pip3 install webdrivermanager
and instantiate chrome driver like this :
driver = webdriver.Chrome(ChromeDriverManager().install())
Related
import time
import self as self
from pytest import mark
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from setuptools import setup
#mark.execute
class First_Tests:
def test_first(self, setup):
driver = setup['driver']
browser = setup['browser']
driver.get("https://shuftipro.com/")
driver.maximize_window()
def header_test(self, setup):
driver = setup['driver']
# Click on solution in header
solution = driver.find_element(By.ID, "menu-item-72751")
solution.click()
if driver.current_url == "https://shuftipro.com/solutions/":
print("land on solution page.")
else:
print("land on wrong page.")
obj = First_Tests()
obj.test_first(self, setup)
obj.header_test(self, setup)
If I remove the "self" from parameter and run the program it showing me error that, test_first() takes 1 positional arguments but 3 were given
one of easier way would be to use webdriver from selenium
driver = webdriver.Chrome()
and remove
driver = setup['driver']
browser = setup['browser']
and then get rid of setup as parameter.
The final code will look something like this:
from pytest import mark
from selenium import webdriver
from selenium.webdriver.common.by import By
driver = webdriver.Chrome()
#mark.execute
class First_Tests:
def test_first(self):
driver.get("https://shuftipro.com/")
driver.maximize_window()
def header_test(self):
# Click on solution in header
solution = driver.find_element(By.ID, "menu-item-72751")
solution.click()
if driver.current_url == "https://shuftipro.com/solutions/":
print("land on solution page.")
else:
print("land on wrong page.")
obj = First_Tests()
obj.test_first()
obj.header_test()
I start to learn selenium today. I install chrome driver and firefox driver accoding to version. I try with both chrome and firefox but browsers closes immediately. I also add drivers to PATH. I also try using direct path of driver
Chrome Version: 109.0.5414.120
Selenium Version: 4.8
Python Version: 3.8
Conda Version: 23.1.0
Code:
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(r"C:\Users\Sarper\Drivers\chromedriver.exe")
print(selenium.__version__) # Verison 4.8
chrome_browser = webdriver.Chrome(service=service)
chrome_browser.get("https://www.google.com")
Seems like it closes, because your code is done running.
You might try:
import selenium
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
service = Service(r"C:\Users\Sarper\Drivers\chromedriver.exe")
print(selenium.__version__) # Verison 4.8
chrome_browser = webdriver.Chrome(service=service)
chrome_browser.get("https://www.google.com")
input("Press ENTER to exit\n")
Service need to get the path to the chromedriver.exe as following:
service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(service=service)
C:\webdrivers\chromedriver.exe here is the actual path to chromedriver.exe on my computer
To keep the browser open set options with detach = true, as wollowing:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
options = Options()
options.add_experimental_option("detach", True)
options.add_argument("start-maximized")
service = Service('C:\webdrivers\chromedriver.exe')
driver = webdriver.Chrome(options=options, service=service)
from selenium import webdriver
# Selenium Version
print(webdriver.__version__)
# Instantiating the Chrome driver
chrome_browser = webdriver.Chrome()
# Opening the browser to Google website
chrome_browser.get("https://www.google.com")
I try to use Python and Selenium, but I get this error: PlacementList must be sorted by first 8 bits of display_id
How can I solve this?
This is the code:
from selenium import webdriver
e = "C:/Downloads/edgedriver_win64/msedgedriver.exe"
driver = webdriver.Edge(e)
driver.get("http://www.python.org")
Try this if it helps
from selenium import webdriver
from webdriver_manager.microsoft import EdgeChromiumDriverManager
driver = webdriver.Edge(EdgeChromiumDriverManager().install())
driver.get("http://www.python.org")
If you want to use chrome as a browser try the following code.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service as ChromiumService
from webdriver_manager.chrome import ChromeDriverManager
from webdriver_manager.core.utils import ChromeType
browser = webdriver.Chrome(service=ChromiumService(ChromeDriverManager(chrome_type=ChromeType.CHROMIUM).install()))
browser.get('www.your-website.com')
However, I advise using Firefox which is the more stable one as follow.
from selenium import webdriver
from selenium.webdriver.firefox.service import Service as FirefoxService
from webdriver_manager.firefox import GeckoDriverManager
driver = webdriver.Firefox(service=FirefoxService(GeckoDriverManager().install()))
# Open the Website
driver.get('https://www.your-website.com')
print(driver.title)
driver.quit()
I'm trying to use webdriver.Chrome() to open the chrome browser,
Its successful but cannot access the url variable.
Chrome popup but cannot access the url
I use this Chrome driver version 92 for windows:
https://chromedriver.storage.googleapis.com/index.html?path=92.0.4515.43/
pip install selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
print('-Finish importing package')
driver = webdriver.Chrome()
url = "youtube.com"
driver.get(url)
Try to give the https/http protocol with the URL, so it should be like below.
url = "https://youtube.com"
Code
pip install selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
print('-Finish importing package')
driver = webdriver.Chrome()
url = "https://youtube.com"
driver.get(url)
#Reference
I'd like to automate the following Linux shell command:
google-chrome-stable --password-store=basic --user-data-dir=/tmp/chrome
using splinter (or selenium), but I cannot find documentation/examples that explain how to pass arguments and values to the Browser command.
The following (wrong) code shows what I tried:
"""
google-chrome-stable --password-store=basic --user-data-dir=/tmp/chrome
"""
from splinter import Browser
from selenium import webdriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_experimental_option("password-store", "basic")
chrome_options.add_experimental_option("user-data-dir", "/tmp/chrome")
browser = Browser('chrome', options=chrome_options)
Can you help with the correct syntax?
This is how it's done:
from splinter import Browser
import selenium.common.exceptions
from selenium import webdriver
def prepare_special_chrome():
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--password-store=basic")
chrome_options.add_argument("--user-data-dir=/tmp/chrome")
browser = Browser('chrome', options=chrome_options)
browser.visit('https://machine.local/#/')
if __name__ == "__main__":
prepare_special_chrome()