Python - InvalidArgumentException - python

I'm trying to start webscraping, but whenever I try to acces an URL I get an error message.
My code is the following:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('www.python.org')
This opens a new Chrome window, but that's all it does.
The error message I get is the following:
InvalidArgumentException: invalid argument
(Session info: chrome=80.0.3987.149)
I work with Spyder, which I get from Anaconda, and my chromedriver.exe is in the both in the Anaconda3 folder and the Spyder folder.
Thanks in advance!

This URL is not Valid , it has to start with http://
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
try:
driver = webdriver.Chrome()
driver.get('http://www.python.org')
except Exception as e:
print(e)
finally:
if driver is not None :
driver.close()

Please include executable path and try below solution:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path=r"C:\New folder\chromedriver.exe")
driver.get("https://www.python.org")
Your url is not correct www.python.org , correct url : https://www.python.org

Related

Selenium does't open firefox

I'm trying use selenium and firefox, but it's just open the browser and set this error:
Error
With Chrome is ok.
This is the code:
from selenium import webdriver
driver = webdriver.Firefox(executable_path = "c:/my-apps/geckodriver.exe")
Thanks very much
When you try to find any element in an HTML page that does not exist, NoSuchElementException will be raised.
First Possible Solution:
You need to import
from selenium.common.exceptions import NoSuchElementException
Then you can use try except block
try:
your_element = driver.find_element_by_xpath(".//*[#id='loginForm:username']")
your_element.click()
except NoSuchElementException:
pass
Second Possible Solution:
Without importing anything, checking whether that element exist, if it does then it will be clicked
your_element = driver.find_elements_by_xpath(".//*[#id='loginForm:username']")
if len(your_element) > 0:
elem[0].click()
HEY You can use this code as given below
driver = webdriver.Firefox()
driver.implicitly_wait(5)
driver.maximize_window()
driver.get('URL')
I think you should put your geckodriver in the same folder where you are coding
and if this does not work you need to upgrade geckodriver
HEY According to your ERROR
when you open the website your 1 element is not correct
you need to change your 1 element of your website
wait=WebDriverWait(self.driver,60)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#loginForm:username"))).send_keys("a")
Generally Firefox is a tad slower than Chrome so your issue may be timing for find elements. What is recommended is waiting for the element to be clickable and then proceeding to send keys to it.
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

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

I am getting error in selenuim. I have latest verion of Chrome: 87.0.4280.66. Selenuim Chrome Version: 87

Here's My Code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = "C:\Program Files (x86)\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(PATH)
try:
driver.get('google.com')
except Exception as e:
print(e)
driver.quit()
And My Console :
*DevTools listening on ws://127.0.0.1:49907/devtools/browser/d1080af1-5c49-4f88-8e6c-976e3440a13c
Message: invalid argument
(Session info: chrome=87.0.4280.66)*
Please Help Me get out of this, Plz
Try to get the page with using the URL scheme, https://
driver.get("https://www.google.com")
Full code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
PATH = r"C:\Program Files (x86)\chromedriver_win32\chromedriver.exe"
driver = webdriver.Chrome(PATH)
try:
driver.get("https://www.google.com")
except Exception as e:
print(e)
driver.quit()

TypeError: get() missing 1 required positional argument: 'url' error using GeckoDriver and Firefox through Selenium and Python

Executing below code in pycharm.
from selenium import webdriver
browser = webdriver.Firefox
browser.get('https://www.google.com')
Error:
TypeError: get() missing 1 required positional argument: 'url'
How can I solve the error?
Specify the path the chrome driver is located in for example when calling
webdriver.Firefox(‘C://Users/Username/Downloads/‘)
This worked for me:
from selenium import webdriver
driver = webdriver.Chrome("C:\\Users\Rishabh\Downloads\chromedriver_win32\chromedriver.exe")
driver.get('https://web.whatsapp.com/')
Alternate code:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="C:\\Users\Rishabh\Downloads\chromedriver_win32\chromedriver.exe")
driver.get('https://web.whatsapp.com/')
In my case, I got this error for not using parenthesis ().
from selenium import webdriver
browser = webdriver.Firefox()
browser.get('https://www.google.com')
Try with braces while creating Firefox instance. see below example.
from selenium import webdriver
browser = webdriver.Firefox() #focus on () at the end
browser.get('https://www.google.com')
The constructor is driver = webdriver.Firefox(). So in your code block you need to replace driver = webdriver.Firefox with:
driver = webdriver.Firefox()
Additionally, you may need to pass the absolute path of the GeckoDriver binary as follows:
driver = webdriver.Firefox(executable_path=r'C:\path\to\geckodriver.exe')
The issue is caused bacause there are not,()pharentesis, put the pharantesis end to the line
Check this
In Selenium and python
driver = webdriver.Chrome()

Python, error with web driver (Selenium)

import time
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome()
driver.get('http://arithmetic.zetamac.com/game?key=a7220a92')
element = driver.find_element_by_link_text('problem')
print(element)
I am getting the error:
FileNotFoundError: [Errno 2] No such file or directory: 'chromedriver'
I am not sure whythis is happening, because I imported selenium already.
Either you provide the ChromeDriver path in webdriver.Chrome or provide the path variable
from selenium import webdriver
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
driverLocation = 'D:\Drivers\chromedriver.exe' #if windows
driver = webdriver.Chrome(driverLocation)
driver.get('http://arithmetic.zetamac.com/game?key=a7220a92')
element = driver.find_element_by_link_text('problem')
print(element)
Best way to eliminate this Exception without altering the code eevn single line is to add the chromedriver.exe( or nay other browser driver files) in to Python
site_packages/scripts directory for windows
dist_package/scripts for Linux
Please check this solution, it works.
If you are using a Mac, then don't include '.exe' I put the selenium package directly into my Pycharm project that I called 'SpeechRecognition'. Then in the selenium file, navigate to: /selenium/webdriver/chrome, then copy and paste the 'chromedriver.exe' file you downloaded most likely from [here][1]
Try this script if you are using PyCharm IDE or similar. This should open a new Google window for you.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome('/Users/Name/PycharmProjects/SpeechRecognition/selenium/webdriver/chrome/chromedriver')
browser.get('http://www.google.com')
Then if you want to automatically search an item on Google, add these lines below and run. You should see an automatic google search window opening up. It might disappear quickly but to stop that, you can simply add a while loop if you want or a timer
search = browser.find_element_by_name('q')
search.send_keys('How do I search an item on Google?')
search.send_keys(Keys.RETURN)
[1]: https://sites.google.com/a/chromium.org/chromedriver/home

Categories