Python - Selenium Fail - python

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
chromedriver = 'C:\chromedriver.exe'
browser = webdriver.Chrome(chromedriver)
I tried running this in CMD, and I get the following error:

Related

InvalidArgumentException: Message: binary is not a Firefox executable error in Python linuxmint environment

I test selenium python and I have these errors with firefox and I can't find the solution. Here my code
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from selenium.webdriver.firefox.firefox_binary import FirefoxBinary
options = Options()
options.binary = FirefoxBinary(r'/usr/bin/firefox')
driver = webdriver.Firefox(executable_path= r'./scrap/geckodriver', options=options)
driver.get("http://www.google.com")
print (driver.page_source.encode('utf-8') )
driver.close()
My error message python linuxmint :
selenium.common.exceptions.InvalidArgumentException: Message: binary is not a Firefox executable
I've been searching the forum for a few days, but I can't find a solution for linux mint.
This is an example of working selenium/Firefox setup on Debian, which should also work on Mint, given it's essentially the same os:
from selenium import webdriver
from selenium.webdriver.firefox.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.firefox.options import Options as Firefox_Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support import expected_conditions as EC
import time as t
import pandas as pd
firefox_options = Firefox_Options()
# firefox_options.add_argument("--width=1280")
# firefox_options.add_argument("--height=720")
driverService = Service('chromedriver/geckodriver') ## path where you saved geckodriver
browser = webdriver.Firefox(service=driverService, options=firefox_options)
Selenium docs: https://www.selenium.dev/documentation/
As an alternative to options.binary = FirefoxBinary() you can use the binary_location option as follows:
options = Options()
options.binary_location = r'/usr/bin/firefox'

Python Selenium Error: PlacementList must be sorted by first 8 bits of display_id

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()

Jupyter - Python 3 - InvalidArgumentException while using "webdriver.Chrome()"

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

Module selenium.webdriver has no attribute "get"

I've been trying to run a script in Python to make Chrome open up to a specific page. Here is my code so far
Code part 1
Code part 2
The code is
from selenium import webdriver as wd
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
Then
driver = wd.Chrome()
driver.implicitly_wait(5)
Then
driver.get("https://www.facebook.com")
Despite the error message in the screenshot after the second cell, Chrome opens when I run the script. It just opens to a blank page. I've tried changing the name of driver and wd and webdriver and I get the "module selenium.webdriver has no attribute "get"" every time. This post from yesterday is similar to what I'm having trouble with
but the solution isn't working for me.
Not sure, but try one of the following:
remove wd as it causing misleading
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
driver = webdriver.Chrome(ChromeDriverManager().install())
driver = webdriver.Chrome()
driver.implicitly_wait(5)
or this
from selenium import webdriver as wd
from webdriver_manager.chrome import ChromeDriverManager
driver = wd.Chrome(ChromeDriverManager().install())
driver = wd.Chrome()
driver.implicitly_wait(5)
But please don't mix between them.
I prefer the first option.

How to install Chrome Extension using Selenium & Python

Hello I'm trying to install a Chrome extension with Selenium using python, I tried using ChromeDriver - WebDriver for Chrome
But it is not working, this is my code:
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import ChromeOptions
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.expected_conditions import presence_of_element_located
import re # regular expressions, are imported from python directly
import time
import numpy as np
import pandas as pd
import functions_database
# Pandas read CSV
df_read = pd.read_csv(
'/home/daniel/amazon-project-scrapers/ss_scraper.edited2.csv')
amazon_data = list(df_read.amz_search)
# Chrome Driver + install plugin
ChromeOptions options = new ChromeOptions();
options.addExtensions(new File("/home/daniel/amazon-project-scrapers/chromedriver_linux64/DS-Amazon-Quick-View_v2.8.9.crx"));
ChromeDriver driver = new ChromeDriver(options);
driver = webdriver.Chrome(executable_path='/home/daniel/amazon-project-scrapers/chromedriver_linux64/chromedriver')
driver.get('https://www.amazon.com/')
And this is the error i'm getting:
File "camel_scraper.py", line 23
ChromeOptions options = new ChromeOptions();
^
SyntaxError: invalid syntax
I tried to do this in other 3 different ways, actually there is a similar question in Stack overflow whose answer is deprecated, if I find it again I'll write the link in here.
To add/install the DS-Amazon-Quick-View Chrome extension using Selenium's python client you can use the following splution:
Code Block:
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
chrome_options = Options()
chrome_options.add_extension('/home/daniel/amazon-project-scrapers/chromedriver_linux64/DS-Amazon-Quick-View_v2.8.9.crx')
driver = webdriver.Chrome(options=chrome_options, executable_path='/path/to/chromedriver')
driver.get('https://www.google.co.in')
Reference
You can find a couple of relevant discussions in:
[Python] How to load extension within chrome driver in selenium with python
[Java] How to install extension permanently in geckodriver

Categories