I am trying to use webdriver to click the login button and the page has transformed correctly.but the program stop and occured the proplem "selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable"
and this is the code where occured problems
browser.find_element_by_xpath(
'//*[#id="emap-rsids-content"]/div/div[3]/div/div[1]/div/div/div/input').send_keys(uid)
browser.find_element_by_xpath(
'//*[#id="emap-rsids-content"]/div/div[3]/div/div[2]/div/div/div/input').send_keys(pwd)
# click to sign in
browser.find_element_by_xpath('//*[#id="emap-rsids-content"]/div/div[3]/div/div[3]/div/button').send_keys(Keys.ENTER)
time.sleep(3)
browser.find_element_by_xpath('/html/body/main/article/section[1]/div/div/div/div[2]/div/div/div[2]/div[2]').click()
this is the traceback
Traceback (most recent call last):
File "C:/Users/14638/Desktop/auto_sign_zzu_jksb-master/auto_sign.py", line 68, in sign_in
time.sleep(3)
File "C:\Users\14638\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\14638\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\14638\AppData\Local\Programs\Python\Python37\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\14638\AppData\Local\Programs\Python\Python37\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=83.0.4103.116)
the line 68 is time.sleep(3), the click works and transform to a new page,but it still occured that the button element is interctable.
I have try two methods, one is
'''
browser.find_element_by_xpath('//*[#id="emap-rsids-content"]/div/div[3]/div/div[3]/div/button').click()
'''
and another is
'''
pages=browser.find_element_by_xpath('//*[#id="emap-rsids-content"]/div/div[3]/div/div[3]/div/button')
browser.execute_script("arguments[0].click();", pages)
'''
but still not work
I think you are trying to click the element which is not completely loaded.What you have to do is wait till that happens.
First import these files
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Then add this after logging in.
WebDriverWait(browser, 10).until(EC.element_to_be_clickable((By.XPATH, '/html/body/main/article/section[1]/div/div/div/div[2]/div/div/div[2]/div[2]')))
Then do
browser.find_element_by_xpath('/html/body/main/article/section[1]/div/div/div/div[2]/div/div/div[2]/div[2]').click()
You need to update the page_source:
browser.find_element_by_xpath(
'//*[#id="emap-rsids-content"]/div/div[3]/div/div[1]/div/div/div/input').send_keys(uid)
browser.find_element_by_xpath(
'//*[#id="emap-rsids-content"]/div/div[3]/div/div[2]/div/div/div/input').send_keys(pwd)
# click to sign in
time.sleep(5) # add some time to load the page
browser.get(browser.current_url)
time.sleep(1)
browser.find_element_by_xpath('//*[#id="emap-rsids-content"]/div/div[3]/div/div[3]/div/button').send_keys(Keys.ENTER)
time.sleep(3)
browser.find_element_by_xpath('/html/body/main/article/section[1]/div/div/div/div[2]/div/div/div[2]/div[2]').click()
Related
I'm trying to get access to this page "fullcollege" with a bot I'm making for students. The problem is that I can't even select an element from it, and this error shows up. I have recently tested my code with another webpages like instagram and everything works perfectly. Anyone knows what can I do to solve this? Thanks in advance.
My code:
from time import sleep
from selenium import webdriver
browser = webdriver.Firefox()
browser.implicitly_wait(5)
browser.get('https://www.fullcollege.cl/fullcollege/')
sleep(5)
username_input = browser.find_element_by_xpath("//*[#id='textfield-3610-inputEl']")
password_input = browser.find_element_by_xpath("//*[#id='textfield-3611-inputEl']")
username_input.send_keys("username")
password_input.send_keys("password")
sleep(5)
browser.close()
The error:
Traceback (most recent call last):
File "c:\Users\marti\OneDrive\Escritorio\woo\DiscordBot\BetterCollege\tester.py", line 11, in <module>
username_input = browser.find_element_by_xpath("//*[#id='textfield-3610-inputEl']")
File "C:\Users\marti\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\marti\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\marti\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\marti\AppData\Local\Programs\Python\Python38\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: //*[#id='textfield-3610-inputEl']
The username and password field is inside and iframe you need to switch it first.
browser.get('https://www.fullcollege.cl/fullcollege/')
WebDriverWait(browser,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#logFrame")))
sleep(5)
username_input = browser.find_element_by_xpath("//input[#id='textfield-3610-inputEl']")
password_input = browser.find_element_by_xpath("//input[#id='textfield-3611-inputEl']")
username_input.send_keys("username")
password_input.send_keys("password")
import below libraries as well.
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
I'm using Selenium with Python to input an address into a textbox within the Glovo page for Madrid. The code I wrote can be seen below, and the error I get is also copied after the code.
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
import time
url = 'https://glovoapp.com/es/es/madrid/'
# open browser
driver = webdriver.Chrome()
# load page
driver.get(url)
# find field
item = driver.find_element_by_class_name('address-input__container')
# select textbox and input text
time.sleep(2)
item.click()
WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "el-input__inner"))
)
item = driver.find_element_by_class_name('el-input__inner')
time.sleep(2)
item.send_keys('Calle')
The error I get is shown below.
Traceback (most recent call last):
item.send_keys('Calle')
File "C:\Users\Usuario\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\Users\Usuario\anaconda3\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\Usuario\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Usuario\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=91.0.4472.124)
Locator you are using is returning 2 different elements. See if this works
item = driver.find_element_by_xpath("//input[#class='el-input__inner' and #data-test-id='address-input-autocomplete']")
item.send_keys("Calle")
Using various xpath for the element address-input__containerand trying to click it is not working while automation and throws ElementNotInteractableException: Message: element not interactable You can refer this question. Applying the same and it works.
from selenium.webdriver.common.action_chains import ActionChains
driver.get("https://glovoapp.com/es/es/madrid/")
box = driver.find_element_by_class_name('address-input__container')
time.sleep(2)
ActionChains(driver).move_to_element(box).click(box).perform()
driver.find_element_by_xpath("//input[#data-test-id='address-input-autocomplete']").send_keys("SampleText")
I'm new to selenium
Here I want to ask about a problem code (actually not mine)
this is the code
aww = email.strip().split('|')
driver = webdriver.Chrome()
driver.get("https://stackoverflow.com/users/signup?ssrc=head&returnurl=%2fusers%2fstory%2fcurrent")
time.sleep(5)
loginform = driver.find_element_by_xpath("//button[#data-provider='google']")
loginform.click()
mailform = driver.find_element_by_id('identifierId')
mailform.send_keys(aww[0])
driver.find_element_by_xpath("//div[#id='identifierNext']").click()
time.sleep(3)
passform = driver.find_element_by_css_selector("input[type='password']")
passform.send_keys(aww[1])
driver.find_element_by_id('passwordNext').click()
time.sleep(3)
driver.get("https://myaccount.google.com/lesssecureapps?pli=1")
open('LIVE.txt', 'a+').write(f"CHECKED : {aww[0]}|{aww[1]}")
time.sleep(3)
lessoff = driver.find_element_by_xpath('//div[#class="hyMrOd "]/div/div/div//div[#class="N9Ni5"]').click()
driver.delete_all_cookies()
driver.close()
I'm using those code for automating turn on the less-secure apps from Gmail
and the error will pop up like this
quote Traceback (most recent call last):
File "C:\Users\ASUS\Downloads\ok\less.py", line 59, in
lessoff = driver.find_element_by_xpath('//div[#class="hyMrOd "]/div/div/div//div[#class="N9Ni5"]').click()
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\ASUS\AppData\Local\Programs\Python\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Users\ASUS\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\ASUS\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.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//div[#class="hyMrOd "]/div/div/div//div[#class="N9Ni5"]"}
(Session info: chrome=86.0.4240.183)
any help gonna be helpfull,sorry for my english before :)
You can simply target this xpath and .click to toggle the less secure apps.
lessoff = driver.find_element_by_xpath("input[type='checkbox']").click()
It looks like it couldn't find the element it's looking for so give some time to load the element. You can check with Wait().until.
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait as wait
wait(driver, 10).until(EC.presence_of_element_located((By.XPATH, 'YOUR_XPATH')))
when you try to click an element make sure it's there. above code will wait until the element located for the 10s if the element not located then it will throw an exception
I am trying to fill in the search input type box with value "fab" and then I want to display the next url with that keyword but I am getting this error for element not interactable. How can I solve this?
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path='C:\\Users\\Mansi Dhingra\\Downloads\\chromedriver')
driver.get("https://www.thenational.ae/search?q=")
print(driver.title)
driver.implicitly_wait(10)
search_bar = driver.find_element_by_xpath('//input[#name="q"]')
print(search_bar)
search_bar.clear()
search_bar.send_keys("fab")
search_bar.send_keys(Keys.RETURN)
print(driver.current_url)
driver.close()
Error:-
Traceback (most recent call last): File "C:/Users/Mansi
Dhingra/Desktop/Projects/api/news/news_python.py", line 10, in
search_bar.clear() File "C:\Users\Mansi Dhingra\Desktop\Projects\api\venv\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 95, in clear
self._execute(Command.CLEAR_ELEMENT) File "C:\Users\Mansi Dhingra\Desktop\Projects\api\venv\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 633, in _execute
return self._parent.execute(command, params) File "C:\Users\Mansi
Dhingra\Desktop\Projects\api\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 321, in execute
self.error_handler.check_response(response) File "C:\Users\Mansi Dhingra\Desktop\Projects\api\venv\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=81.0.4044.92)
Whenever webelement is found but not ready to interact then webdriver will throw element not intractable exception.
1.Mostly it occurs, when element is located in bottom of the page, so it can be accessible by scrolling the page down. You can use Action class to scroll to scroll to that element
WebElement element = driver.findElement(By.id("my-id"));
Actions actions = new Actions(driver);
actions.moveToElement(element);
## actions.click();
actions.perform();
2. Sometimes we need to wait few seconds to access the web element, in such situations we can add wait statements.
wait = WebDriverWait(driver, 10)
element = wait.until(EC.element_to_be_clickable((By.ID, 'someid')))
I am trying to make a python program using Selenium to automate the UnovaRPG game. It is supposed to do the following in order:
1) Login with username and password.
2) Go to heal center and click heal.
3) Fight the trainer "shedinja144" (using given link)
4) Select a specified pokemon.
5) During the fight, it should click the last attack followed by continue.
6) Then click "Back to map" for the last pokemon (The 6th).
7) Repeat steps 2-5 any given number of times.
Here is my code:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://www.unovarpg.com/login.php")
assert "UnovaRPG" in driver.title
i=1
j=1
typeUsername = driver.find_element_by_id("username")
typePassword = driver.find_element_by_id("password")
typeUsername.send_keys("******")
typePassword.send_keys("******")
driver.find_element_by_id("buttonLogin").click()
while i<10:
driver.get("https://www.unovarpg.com/pokemon_center.php")
driver.find_element_by_id("healButton").click()
driver.get("https://www.unovarpg.com/battle.php?type=autotrainer&tid=5546527")
driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[3]/div/div/div[2]/div[2]/div[8]/div[4]/div[1]/img").click()
while j<6:
driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[3]/div/div/div[2]/div[2]/div[4]/div[6]/div[2]/ul/li[4]/a/strong").click()
driver.find_element_by_id("continue").click()
j+=1
driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[3]/div/div/div[2]/div[2]/div[4]/div[6]/div[2]/ul/li[4]/a/strong").click()
driver.find_element_by_id("Back2MapButton").click()
i+=1
Here is the error:
Traceback (most recent call last):
File "Selenium v1.py", line 21, in <module>
driver.find_element_by_xpath("/html/body/div[3]/div[2]/div[3]/div/div/div[2]/div[2]/div[8]/div[4]/div[1]/img").click()
File "E:\Programming\Python\Portable Python 2.7.6.1\App\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 230, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "E:\Programming\Python\Portable Python 2.7.6.1\App\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 662, in find_element
{'using': by, 'value': value})['value']
File "E:\Programming\Python\Portable Python 2.7.6.1\App\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 173, in execute
self.error_handler.check_response(response)
File "E:\Programming\Python\Portable Python 2.7.6.1\App\lib\site-packages\selenium-2.44.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 166, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: {"method":"xpath","selector":"/html/body/div[3]/div[2]/div[3]/div/div/div[2]/div[2]/div[8]/div[4]/div[1]/img"}
Stacktrace:
at FirefoxDriver.prototype.findElementInternal_ (file:///c:/users/adb/appdata/local/temp/tmpo1kmq3/extensions/fxdriver#googlecode.com/components/driver-component.js:9641:26)
at FirefoxDriver.prototype.findElement (file:///c:/users/adb/appdata/local/temp/tmpo1kmq3/extensions/fxdriver#googlecode.com/components/driver-component.js:9650:3)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/adb/appdata/local/temp/tmpo1kmq3/extensions/fxdriver#googlecode.com/components/command-processor.js:11635:16)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/adb/appdata/local/temp/tmpo1kmq3/extensions/fxdriver#googlecode.com/components/command-processor.js:11640:7)
at DelayedCommand.prototype.execute/< (file:///c:/users/adb/appdata/local/temp/tmpo1kmq3/extensions/fxdriver#googlecode.com/components/command-processor.js:11582:5)
***Repl Closed***
The error lies in the inability to find the image of the pokemon to click (Step 4). I have used the xcode path copied from the Firebug inspector.
Help would be much appreciated.
Please note that this is just for creative purposes and will not be used to "cheat".
You need to explicitly wait for the element to load before interacting with it:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.XPATH, "/html/body/div[3]/div[2]/div[3]/div/div/div[2]/div[2]/div[8]/div[4]/div[1]/img"))
)