ElementNotInteractableException using selenium library with python - python

from selenium import webdriver
from info import user_name, pass_word
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
import time
driver = webdriver.Firefox() #opening web browser
driver.get('https://tuportal.temple.edu/') #going to temple wbsite
username = driver.find_element_by_id("username") #finds space where to enteruser
password = driver.find_element_by_id("password") #same for password
username.send_keys(user_name()) #enters my username
password.send_keys(pass_word()) #enters my password
driver.find_element_by_name("_eventId_proceed").click()#click login
#waits until the element for student tools tab is found
element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "layout_8")))
element.click()
time.sleep(3)
driver.switch_to_frame("iFrame_AppTupChannelsStudentRegistration")#accessing iframe
#scrolls
element = driver.find_element_by_id('StudentRegistration_3')
driver.execute_script("return arguments[0].scrollIntoView();", element)
#end of scroll
element.click() #click look up classes
All of the code works up until the last line, "element.click()"
I am getting an error -->
Traceback (most recent call last):
File "C:\Users\Karl\Desktop\project\signin.py", line 31, in
element.click() #click look up classes
File "C:\Users\Karl\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\Karl\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:\Users\Karl\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "C:\Users\Karl\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element could not be scrolled into view
The confusing part is the 2 lines right before the line that causes the error are
element = driver.find_element_by_id('StudentRegistration_3')
driver.execute_script("return arguments[0].scrollIntoView();", element)
which do exactly what the error says hasn't happened, they scroll the the button I am trying to click on with the last line into view.
Can anyone identify a solution?
I am using python 3, selenium and Firefox are updated to current versions.

Related

element not interactable selenium python3.9

I tried to automate the login to the site using Selenium, everything worked well on other sites.
When I tried to enter my username in the field I encountered an error :
File "C:\Users\BOY4ik\PycharmProjects\pythonProject\main.py", line 17, in <module>
input_login.send_keys('u.t.x.c.x.z.2.9.0#gmail.com')
File "C:\Users\BOY4ik\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\Users\BOY4ik\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\BOY4ik\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\BOY4ik\AppData\Local\Programs\Python\Python39\lib\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=91.0.4472.101)
Link: https://all-access.wax.io/
MY CODE
browser = webdriver.Chrome()
browser.get('https://all-access.wax.io/')
time.sleep(2)
input_login = browser.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[5]/div/div/div/div[1]/div[1]/input')
browser.execute_script("arguments[0].click();", input_login)
input_login.send_keys('LOGIN')
input_pass = browser.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[5]/div/div/div/div[1]/div[2]/input')
input_pass.send_keys('PASS')
time.sleep(30)
sign_up=browser.find_element_by_xpath('/html/body/div[1]/div/div/div[2]/div[5]/div/div/div/div[5]/button[2]')
sign_up.click()
time.sleep(1)
browser.switch_to.window(browser.window_handles[0])
Okay The below solution assumes that OP can handle captcha using AntiCaptcha.
wait = WebDriverWait(driver, 10)
driver.get("https://all-access.wax.io")
wait.until(EC.element_to_be_clickable((By.NAME, "userName"))).send_keys("Login user name here")
wait.until(EC.element_to_be_clickable((By.NAME, "password"))).send_keys("Login password here")
and OP will handle captcha here :
then click on Login button like this :
ActionChains(driver).move_to_element(wait.until(EC.element_to_be_clickable((By.XPATH, "//button[text()='Login']")))).click().perform()
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.action_chains import ActionChains

"Element <> could not be scrolled into view" error not responding to usual solutions

I'm using selenium to design a scraper to mass-download podcast episodes from Spreaker.
# https://www.spreaker.com/show/alabamas-morning-news-with-jt
for i in range(3):
print("Click number: {}".format(str(i)))
see_more = browser.find_element_by_id("show episodes more")
see_more.click()
browserPage = bs4(browser.page_source, 'lxml')
allEps.append( allEpisodesOnPage(browserPage) )
Since they aren't all on numbered pages (/episodes/page1, /page2), I have to click a button to load more.
But for some reason, my code can't find the button:
Traceback (most recent call last):
File "KeepTalking__02.py", line 59, in <module>
see_more.click()
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/dist-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: Element <a id="show_episodes_more" class="btnn btnn_alternative btnn_small" href="#"> could not be scrolled into view
Now, "could not be scrolled into view" is a standard error in Selenium, and I was inundated with possible solutions:
Scroll the element into view.
Wait for the element to become visible:
element = WebDriverWait(browser, 10).until(
ex_co.presence_of_element_located((By.CSS_SELECTOR, "#show_episodes_more")))
Switch to the frame that it's on.
But for some reason, I'm still getting the exact same error. What could cause this? I took a screenshot and the button was on the page, so I don't understand where the error is coming from.
Basically ElementNotInteractableException is occurs when emporary Overlay of other WebElement over the WebElement. To avoid ElementNotInteractableException you can use ActionChains please refer below solution :
element = WebDriverWait(browser, 10).until(
ex_co.presence_of_element_located((By.CSS_SELECTOR, "#show_episodes_more")))
ActionChains(driver).move_to_element(element).click().perform()
Note : please add below imports to your solution
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
or
element= wait(self.browser,30).until(EC.element_to_be_clickable((By.XPATH,"//a[#id='show_episodes_more']")))
driver.execute_script("arguments[0].click();", element)

Selenium not finding link element

I'm trying to click the "Login" button on this website, with Selenium : https://results.decisiondeskhq.com/2020/primary/colorado/president. I right clicked the element in inspect element, copied the xpath, and put it into the find_element_by_xpath function.
Here's my code:
from selenium import webdriver
driver = webdriver.Chrome(executable_path="/users/aliallam/Desktop/scraper test/chromedriver")
url = 'https://results.decisiondeskhq.com/2020/primary/colorado/president'
driver.get(url)
driver.find_element_by_xpath('//*[#id="content"]/div/div/div/div/button').click()
This is the error message I get:
Traceback (most recent call last):
File "/Users/aliallam/Desktop/scraper test/sandbox2.py", line 7, in <module>
driver.find_element_by_xpath('//*[#id="content"]/div/div/div/div/button').click()
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "/Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
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.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#id="content"]/div/div/div/div/button"}
(Session info: chrome=80.0.3987.149)
Thank you in advance!
You need to wait until the webpage load to select the button. You need to import
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
adding the delay and wait before select the element like this:
delay = 10 # seconds
WebDriverWait(driver, delay).until(
EC.presence_of_element_located((By.CLASS_NAME, 'signup-boxes')))
# you can select element that you want ini here
for more resource visit here
The element has an unique id, so instead of using xpath, you should use the id and you should apply explicit wait on the element so that the script waits until the element is present and as there is a div of element present above the element that you are trying to click, you need to use java script click in this case.
Your code should be like:
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
driver = webdriver.Chrome(executable_path="/users/aliallam/Desktop/scraper test/chromedriver")
url = 'https://results.decisiondeskhq.com/2020/primary/colorado/president'
driver.get(url)
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.ID, "login-text-btn")))
driver.execute_script("arguments[0].click();", element)

Element not interactable when trying to access a pop-up with Selenium

I am trying to scrape the following website: https://www.nemlig.com/ but it is not as easy as I was used to, as the page I am trying to scrape things off is not static. What I am trying to do using Selenium is click this:
So that the zipcode pop-up is visible. Then, insert a number and hit enter.
This is my take on it:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome(executable_path=r"C:\Users\user\lib\chromedriver_77.0.3865.40.exe")
browser.get('https://www.nemlig.com/')
elem = browser.find_element_by_xpath("//div[#class='timeslot-statusbutton']")
elem.clear()
elem = browser.find_element_by_xpath("//input[#class='prompt__input ng-pristine ng-valid ng-empty ng-touched']")
elem.send_keys("2300")
elem.send_keys(Keys.RETURN)
But everything after browser.get returns me this error:
Traceback (most recent call last):
File "", line 8, in
elem = browser.find_element_by_xpath("//div[#class='timeslot-statusbutton']").click()
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "D:\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
ElementNotInteractableException: element not interactable
(Session info: chrome=77.0.3865.90)
How can I do this properly?
You can try this code :
driver = webdriver.Chrome(executable_path = r'C:/Users/***/Downloads/BrowserDriver/chromedriver_win32/chromedriver.exe')
wait = WebDriverWait(driver,10)
driver.maximize_window()
driver.get("https://www.nemlig.com/")
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".timeslot-prompt.initial-animation-done")))
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[type='tel'][class^='pro']"))).send_keys('ABC')
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".btn.prompt__button"))).click()
imports will be :
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

Selenium Python 3.4.3 Loging into Gmail: Password section

So below is my code so far. It is supposed to go to the website and login with all the necessary details but i keep on getting huge chunks of errors! I dont understand where the error is hiding, anyone who sees it please help. Thanks!
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
browser = webdriver.Firefox()
from selenium.webdriver.common.keys import Keys
#browser.get('https://mail.yahoo.com')
browser.get('https://accounts.google.com/ServiceLogin?sacu=1&scc=1&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&hl=en&service=mail#identifier')
emailElem = browser.find_element_by_id('Email')
emailElem.send_keys('email_address')
nextButton = browser.find_element_by_id('next')
nextButton.click()
passwordElem = browser.find_element_by_id('Passwd')
wait = WebDriverWait(browser, 10)
passwordElem = wait.until(EC.visibility_of_element_located((By.ID, "Passwd")))
passwordElem.clear()
passwordElem.send_keys('12345')
SignIn = browser.find_element_by_id('signIn')
SignIn.click()
#passwordElem.clear()
#passwordElem.send_keys('12345')
#SignIn = browser.find_elements_by_id('signIn')
#SignIn.click()
#passwordElem.submit()
This is the error i am receiving:
Traceback (most recent call last):
File "C:/Users/hp-450/Desktop/Automating_Gmail.py", line 15, in <module>
passwordElem = browser.find_element_by_id('Passwd')
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 266, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 744, in find_element
{'using': by, 'value': value})['value']
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "C:\Python34\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"id","selector":"Passwd"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///C:/Users/hp-450/AppData/Local/Temp/tmp3awlgy5b/extensions/fxdriver#googlecode.com/components/driver-component.js:10770)
at FirefoxDriver.prototype.findElement (file:///C:/Users/hp-450/AppData/Local/Temp/tmp3awlgy5b/extensions/fxdriver#googlecode.com/components/driver-component.js:10779)
at DelayedCommand.prototype.executeInternal_/h (file:///C:/Users/hp-450/AppData/Local/Temp/tmp3awlgy5b/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///C:/Users/hp-450/AppData/Local/Temp/tmp3awlgy5b/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///C:/Users/hp-450/AppData/Local/Temp/tmp3awlgy5b/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
After you enter your email and submit the form, wait for the password field to be visible:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# wait for the password field to be visible
wait = WebDriverWait(browser, 10)
passwordElem = wait.until(EC.visibility_of_element_located((By.ID, "Passwd")))
passwordElem.clear()
passwordElem.send_keys('12345')
SignIn = browser.find_element_by_id('signIn')
SignIn.click()
Also note that you have to use find_element_by_id() instead of the find_elements_by_id() method to locate the "Sign In" button.

Categories