Selenium Python Error - python

I am trying to create a small test program that is able to login into gmail. So far the program opens up the website on chrome but then fails to actually type anything into the "Enter Email" form box. Also I am receiving an error within the shell which may provide insight into my question.
Driver Version: 2.40
Chrome Version: 67.0.3396.99
Below is the code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver= webdriver.Chrome('C:\chromedriver_win32\chromedriver.exe')
driver.get("http://mail.google.com")
emailid=driver.find_element_by_name("identifier")
emailid.send_keys("samplekeys")
Below is the error:
Traceback (most recent call last):
File "C:\gmail.py", line 7, in <module>
driver.get("http://mail.google.com")
File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 332, in get
self.execute(Command.GET, {'url': url})
File "C:\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: missing or invalid 'entry.level'
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.27.440174 (e97a722caafc2d3a8b807ee115bfb307f7d2cfd9),platform=Windows NT 10.0.17134 x86_64)
Any help would be greatly appreciated!

try this :
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
browser = webdriver.Chrome(executable_path = r'C:/chromedriver_win32/chromedriver.exe')
browser.get("http://mail.google.com")
wait = WebDriverWait(browser, 10)
user_name = wait.until(EC.element_to_be_clickable((By.ID, 'identifierId')))
user_name.click()
user_name.send_keys("samplekeys")

You need to download the chromedriver, and put the path to your webdriver.Chrome(), for example my chromedriver are in /usr/local/bin/chromdriver
driver = webdriver.Chrome('/usr/local/bin/chromedriver')
or for widndows
driver = webdriver.Chrome(executable_path = r'C:\chromedriver_win32\chromedriver.exe')

Related

Selenium.common.exceptions.WebDriverException: Message: unknown error: no chrome binary

I'm trying to run a python script I made a few months ago which uses selenium to scrape a web page. Here's my code:
import pandas as pd
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
driver = webdriver.Chrome(executable_path="/users/aliallam/Documents/chromedriver")
Here's the full error I'm getting:
Traceback (most recent call last):
File "/Users/aliallam/Desktop/MISOS_Python_Scraper/main.py", line 16, in <module>
driver = webdriver.Chrome(executable_path="/users/aliallam/Documents/chromedriver")
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/chrome/webdriver.py", line 76, in __init__
RemoteWebDriver.__init__(
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
self.start_session(capabilities, browser_profile)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
response = self.execute(Command.NEW_SESSION, parameters)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary
I tried the solution under this question, but still no luck: Selenium gives "selenium.common.exceptions.WebDriverException: Message: unknown error: cannot find Chrome binary" on Mac
Here's what I changed my code to:
options = webdriver.ChromeOptions()
options.binary_location = " /Applications/Google\ Chrome\ 2.app"
chrome_driver_binary = "/users/aliallam/Documents/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary,chrome_options=options)
This is really frustrating, some help would be much appreciated! Thanks in advance!
EDIT: In addition to the following mistake, I think you also need to change the binary location to be /Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome
Based on what you posted, I think the error is because of an extra space located after the first quotation mark in this line:
options.binary_location = " /Applications/Google\ Chrome\ 2.app"
Try changing that to:
options.binary_location = "/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome"
and rerunning the code.
Full code based on what you provided:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome"
chrome_driver_binary = "/users/aliallam/Documents/chromedriver"
driver = webdriver.Chrome(chrome_driver_binary,chrome_options=options)
If that doesn't work, you could also try
from selenium import webdriver
options = webdriver.ChromeOptions()
options.binary_location = "/Applications/Google Chrome 2.app/Contents/MacOS/Google Chrome"
executable_path = "/users/aliallam/Documents/chromedriver"
driver = webdriver.Chrome(executable_path=executable_path, chrome_options=options)
For me on MacOS the error got solved when I moved my downloaded "Google Chrome" application from "Downloads" folder to "Applications" Folder

Python Selenium - Unable to locate element

I just started learning selenium and I'm facing some issues with some code that should be quite easy to write..
I'm simply trying to enter "Paris" in the input field, but I keep getting the error: "Unable to locate element". Do I need to refer to the div tag or the input tag in order for it to work?
Here's my code at the moment.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC
import time
# Setup webdriver
PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)
# Open website maximized
driver.get("https://www.corsair.ca/")
driver.maximize_window()
print(driver.title)
# Select and enter destination
wait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='Votre destination']"))).click()
to_city = driver.find_element_by_class_name("form-control valid")
to_city.send_keys("Paris")
to_city.send_keys(Keys.RETURN)
Here's the error I have
Traceback (most recent call last):
File "C:\Users\Admin\PycharmProjects\FlightFinder\venv\SeleniumTutorial.py", line 26, in <module>
to_city = driver.find_element_by_class_name("form-control valid")
File "C:\Users\Admin\PycharmProjects\FlightFinder\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 564, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name)
File "C:\Users\Admin\PycharmProjects\FlightFinder\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\Admin\PycharmProjects\FlightFinder\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Admin\PycharmProjects\FlightFinder\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".form-control valid"}
(Session info: chrome=86.0.4240.183)

Message: element not intractable still not working even after a time.sleep() and WebDriverWait

I know this has been asked lots of times before but how do you get around the "element not intractable" exception?
I'm pretty new to Selenium so excuse me if I get something wrong or misunderstood.
I have tried adding time.sleep(20) in various parts of the code to see if this allows the element to load but no success as yet.
Am I missing something here?
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
#Login Credentials
email = 'anexample#fakeemail.com'
password = 'Password123'
#Login to Money Dashboard
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
driver.get("https://my.moneydashboard.com/")
loginPageEmail = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.XPATH, '//*[#id="input_0"]')))
loginPageEmail.send_keys(email)
I always get an error along the lines of:
Traceback (most recent call last):
File "mdash.py", line 26, in <module>
loginPageEmail.send_keys(email)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py",
line 479, in send_keys
'value': keys_to_typing(value)})
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webelement.py",
line 633, in _execute
return self._parent.execute(command, params)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/webdriver.py",
line 321, in execute
self.error_handler.check_response(response)
File "/Library/Python/2.7/site-packages/selenium/webdriver/remote/errorhandler.py",
line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=75.0.3770.100)
(Driver info: chromedriver=74.0.3729.6 (255758eccf3d244491b8a1317aa76e1ce10d57e9-refs/branch-heads/3729#{#29}),platform=Mac
OS X 10.13.6 x86_64)
If you check the element id attribute is dynamic every time you run the code.So name attribute should be unique attribute here to access the input element .However Without form element it is not identifying the input element so I have used the form element along with input element and unique property of input element.
Use WebdriverWait and elementtobeclickable and following xpath.
email = 'anexample#fakeemail.com'
password = 'Password123'
#Login to Money Dashboard
driver = webdriver.Chrome(executable_path='/usr/local/bin/chromedriver')
driver.get("https://my.moneydashboard.com/")
loginPageEmail = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//form[#name="vm.registerForm"]//div[#class="inputs"]//input[#name="email"]')))
loginPageEmail.send_keys(email)
loginPagepassword = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//form[#name="vm.registerForm"]//div[#class="inputs"]//input[#name="password"]')))
loginPagepassword.send_keys(password)
Output:

Python with Selenium: Unable to find element to type in

I'm trying to find an element on website using Selenium but am having a hard time:
The page I'm looking at: https://corporate.axisbank.co.in/
The HTML from the selected element looks as follows:
<input name="FORM_CORPORATEID" type="text" onpaste="return false" ondrop="return false" ondrag="return false" oncopy="return false" oncut="return false" autocomplete="off" id="corporateId" class="cm-input-box has-gradient-border">
I've tried using Id, XPath etc but keep getting errors:
from selenium import webdriver
driver = webdriver.Chrome()
bankurl= "https://corporate.axisbank.co.in/"
driver.get(bankurl)
driver.find_element_by_name("FORM_CORPORATEID").send_keys("USERNAME")
I end up getting the following error:
Traceback (most recent call last):
File "C:/Users/alwyn.kotze/PycharmProjects/AlwynAuto1/Automations/Axis1.py", line 8, in <module>
driver.find_element_by_name("FORM_CORPORATEID").send_keys("USERNAME")
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 489, in find_element_by_name
return self.find_element(by=By.NAME, value=name)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 957, in find_element
'value': value})['value']
File "C:\Python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 314, in execute
self.error_handler.check_response(response)
File "C:\Python\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"name","selector":"FORM_CORPORATEID"}
(Session info: chrome=66.0.3359.181)
(Driver info: chromedriver=2.38.552522 (437e6fbedfa8762dec75e2c5b3ddb86763dc9dcb),platform=Windows NT 10.0.16299 x86_64)
What could be causing this error?
As per the HTML you have provided to find the element and send the text USERNAME you need to induce WebDriverWait for the element to be clickable as follows:
Code Block:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome()
bankurl= "https://corporate.axisbank.co.in/"
driver.get(bankurl)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#corporateId"))).send_keys("USERNAME")
Browser Snapshot:
from selenium import webdriver
import time
driver = webdriver.Chrome()
bankurl= "https://corporate.axisbank.co.in/"
driver.get(bankurl)
time.sleep(5)
driver.find_element_by_id('corporateId').send_keys("USERNAME")

Unable to upload image in selenium python

The Code i am using:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains
import time
wait = WebDriverWait
chrome_options = webdriver.ChromeOptions()
prefs = {"profile.default_content_setting_values.notifications": 2}
chrome_options.add_experimental_option("prefs", prefs)
chrome_options.add_argument("start-maximized")
chrome_options.add_argument("--incognito")
driver = webdriver.Chrome(chrome_options=chrome_options,
executable_path=r'C:\\chromedriver\\chromedriver.exe')
driver.maximize_window()
driver.get("https://www.arttoframe.com/canvas_acrylic/")
driver.switch_to_frame("Uploadimage")
driver.find_element_by_xpath('//*[ # id = "dropTarget"] / img').send_keys("C:\\Users\\Dell\\Downloads\\340.JPG")
Error:
C:\Users\Dell\PycharmProjects\ATF_TestOrder\venv\Scripts\python.exe
C:/Users/Dell/PycharmProjects/ATF_TestOrder/ATF_TestOrder/ATF_TestOrder.py
Traceback (most recent call last): File
"C:/Users/Dell/PycharmProjects/ATF_TestOrder/ATF_TestOrder/ATF_TestOrder.py",
line 18, in
driver.switch_to_frame("Uploadimage") File "C:\Users\Dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 775, in switch_to_frame
self._switch_to.frame(frame_reference) File "C:\Users\Dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\switch_to.py",
line 89, in frame
self._driver.execute(Command.SWITCH_TO_FRAME, {'id': frame_reference}) File
"C:\Users\Dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 312, in execute
self.error_handler.check_response(response) File "C:\Users\Dell\AppData\Local\Programs\Python\Python36-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 242, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchFrameException: Message: no such
frame (Session info: chrome=65.0.3325.181) (Driver info:
chromedriver=2.37.544315
(730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT
10.0.16299 x86_64)
I may be wrong, but i think you have to find the iframe first and switch to it
driver.switch_to_frame(driver.find_element_by_id('Uploadimage'))
assuming Uploadimage is an id, you may have to change this one
The website is still valid, so I give it a try, and it is working with below script. The input element for file can't be set in code, so I use send_text to simulate user input.
from clicknium import clicknium as cc
if not cc.chrome.extension.is_installed():
cc.chrome.extension.install_or_update()
browser = cc.chrome.open(url="https://www.arttoframe.com/canvas_acrylic/")
browser.find_element_by_xpath('//*[#id="imageUploadNameText"]').click()
browser.find_element_by_xpath('//*[#id="Upload_content"]/div[1]/div/button').click(by='mouse-emulation')
cc.send_text(r'"C:\Users\Dell\Downloads\340.JPG"')
cc.send_hotkey('{Enter}')
browser.find_element_by_xpath('//*[#id="Edit_content"]/div[3]/ul/li[5]/button').click()

Categories

Resources