from selenium import webdriver
import time
import os, time
driver = webdriver.Chrome(executable_path=r"C:\Users\carlo\OneDrive\Escritorio\chromedriver.exe")
driver.get("https://web.whatsapp.com/")
time.sleep(10)
name = 'me'
user = driver.find_elements_by_xpath('//span[#title = "{}"]'.format(name))[0]
user.click()
msj_box = driver.find_element_by_xpath('//div[#class="_2FbwG"]')
msj_box.send_keys('la caja')
msj_box = driver.find_element_by_xpath('//button[#class="_1U1xa"]')
msj_box.click()
This got probleman when is running the following line
msj_box.send_keys('la caja')
And the output is this
File "c:/Users/carlo/OneDrive/Escritorio/wp3.py", line 23, in <module>
msj_box.send_keys('la caja')
File "C:\MIS programas\python\lib\site-packages\selenium\webdriver\remote\webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "C:\MIS programas\python\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\MIS programas\python\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\MIS programas\python\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)
Please help
It seems the reason you are getting the error is because you are using the method SendKeys with a Div element rather than to an input or text area.
msj_box = driver.find_element_by_xpath('//div[#class="_2FbwG"]')
Related
I am facing a issue while calling xpath, i got the current xpath element by using selectorshub to get the xpath, but seems that not correct.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
driver_service = Service(executable_path="C:\Program Files (x86)\chromedriver.exe")
driver = webdriver.Chrome(service=driver_service)
PASSWORD = 'testtes'
login_page = 'http://192.168.2.1/login.html'
driver.get(login_page)
driver.find_element(By.XPATH,"//input[#placeholder='Password']").send_keys(PASSWORD)
Below is the error i'm getting
Traceback (most recent call last):
File "C:\Users\admin\Desktop\pyhton\index.py", line 13, in <module>
driver.find_element(By.XPATH, "//input[#placeholder='Password']").send_keys(PASSWORD)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 856, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 429, in execute
self.error_handler.check_response(response)
File "C:\Python310\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 243, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[#placeholder='Password']"}
(Session info: chrome=107.0.5304.88)
Stacktrace:
Backtrace:
There is the screenshot of the HTML code from where i am trying to get the xpath from screenshot
I am trying to send some keystrokes using python webdriver to a p element that is attached to a js event listener. When i type the keys in manually, it works. However when I use driver.send_keys(), it returns an ElementNotInteractableException. The element is as follows:
<p data-v-6779462c="" id="textBox" class="input"></p>
My code to locate and send the keystrokes to the element is as follows:
input_area = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//p[#id="textBox"]')))
input_area.click()
input_area.send_keys(keys)
input_area.send_keys(Keys.ENTER)
The full stacktrace is as follows:
Traceback (most recent call last):
File "automation.py", line 32, in <module>
input_area.send_keys(word)
File "/home/server/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "/home/server/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/home/server/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/server/.local/lib/python3.8/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=87.0.4280.66)
I am using Chrome on Ubuntu Linux.
I need the way to solve this and why it is happening.
Thanks in advance!
P tag is a paragraph tag , you cannot Interact with it .
You should be sending keys to input tag
Try below code
input_area.click()
elemInput = driver.switch_to.active_element
elemInput.send_keys(Keys.ENTER)
PyCharm Code:
from appium import webdriver
desired_caps = {}
desired_caps['platformName'] = 'Android'
desired_caps['automationName'] = 'UiAutomator2'
desired_caps['platformVersion'] = '10'
desired_caps['deviceName'] = 'AppiumEmulator'
desired_caps['app'] = ('G:\\Appium\\KickStartAppium\\Android_Demo_App.apk')
desired_caps['appPackage'] = 'com.google.android.apps.nexuslauncher'
desired_caps['appActivity'] = 'com.google.android.apps.nexuslauncher.NexusLauncherActivity'
desired_caps['udid'] = 'emulator-5554'
driver = webdriver.Remote('http://127.0.0.1:4723/wd/hub', desired_caps)
driver.implicitly_wait(10)
ClickEle = driver.find_element_by_id("com.code2lead.kwad:id/EnterValue")
ClickEle.click()
PyCharm Error:
"C:\Users\Nandha Kumar\PycharmProjects\AppiumLaunchApp\venv\Scripts\python.exe" "C:/Users/Nandha Kumar/PycharmProjects/AppiumLaunchApp/KickStartApp.py"
Traceback (most recent call last):
File "C:/Users/Nandha Kumar/PycharmProjects/AppiumLaunchApp/KickStartApp.py", line 19, in <module>
ClickEle = driver.find_element_by_id("com.code2lead.kwad:id/EnterValue")
File "C:\Users\Nandha Kumar\PycharmProjects\AppiumLaunchApp\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 360, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Users\Nandha Kumar\PycharmProjects\AppiumLaunchApp\venv\lib\site-packages\appium\webdriver\webdriver.py", line 279, in find_element
return self.execute(RemoteCommand.FIND_ELEMENT, {
File "C:\Users\Nandha Kumar\PycharmProjects\AppiumLaunchApp\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Nandha Kumar\PycharmProjects\AppiumLaunchApp\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 31, in check_response
raise wde
File "C:\Users\Nandha Kumar\PycharmProjects\AppiumLaunchApp\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 26, in check_response
super().check_response(response)
File "C:\Users\Nandha Kumar\PycharmProjects\AppiumLaunchApp\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: An element could not be located on the page using the given search parameters.
Seems like Selenium didn't find your specified element here:
ClickEle = driver.find_element_by_id("com.code2lead.kwad:id/EnterValue")
selenium then always throws an exception and ends the program. If you want the code to go on you have to import the NoSuchElementException from selenium and do it like this:
Import the Exception first:
from selenium.common.exceptions import NoSuchElementException
and then you can reference it
except NoSuchElementException:
# handle the element not existing
my answer is just copied from this kind gentlemans answer (1st answer): python selenium webscraping "NoSuchElementException" not recognized
I am new in programming (specifically Python Selenium), I have a question regarding pasting a data into an input box, it seems not working if I will paste data on another website, I will received an error. But if I use just one website (either of the two) in pasting the data it is working fine.
Here is my codes below.
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Users\Pashu\AppData\Local\Programs\Python\Python37\chromedriver.exe')
driver.get('https://tinyurl.com/')
inline_tinysite = driver.find_element_by_xpath('//*[#id="url"]')
inline_tinysite.send_keys("https://www.teamxtools.com/content/images/project-7/stack-324/exif/2dehands-velgen-volkswagen-golf-7.jpg")
submit = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/div[2]/div[2]/form/input[3]')
submit.click()
driver.execute_script("window.open('https://cutt.ly/', 'new window')")
inline_cuttly = driver.find_element_by_xpath('//*[#id="link"]')
inline_cuttly.send_keys("https://www.teamxtools.com/content/images/project-7/stack-324/exif/2dehands-velgen-volkswagen-golf-7.jpg")
submit2 = driver.find_element_by_xpath('/html/body/div[1]/section[1]/div/div/div/div/div/button')
submit2.click()
#time.sleep(8)
Here is the error message as text:
C:\Users\Pashu\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/Pashu/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/Helloworld.py
Traceback (most recent call last):
File "C:/Users/Pashu/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/Helloworld.py", line 14, in <module>
inline_cuttly = driver.find_element_by_xpath('//*[#id="link"]')
File "C:\Users\Pashu\PycharmProjects\untitled\venv\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\Pashu\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\Pashu\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Pashu\PycharmProjects\untitled\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":"xpath","selector":"//*[#id="link"]"}
(Session info: chrome=81.0.4044.138)
Process finished with exit code 1
it was stuck on window 1, that is why element //*[#id="link"] is not found. I just added
driver.switch_to.window(driver.window_handles[1])
for it to search on the second window.
I try to publish gist on gist.github.com using python/selenium,
This is my current code :
driver.find_element(By.NAME, "gist[contents][][name]").send_keys("file.md")
#import pdb; pdb.set_trace()
tmp = driver.find_element(By.NAME, "gist[contents][][value]").send_keys("Description file")
#keyboard.write("Description file")
driver.find_element(By.XPATH, "//button[#name=\'gist[public]\']").click()
time.sleep(30)
The code is paritial working, i have big problem on gist[contents][][name] input, app kill and return me this error : is not reachable by keyboard... i don't have ideea how i can fix this error, does anyone know how i can solve this problem?
full error :
admin$ python github_login.py
Traceback (most recent call last):
File "github_login.py", line 31, in <module>
tmp = driver.find_element(By.NAME, "gist[contents][][value]").send_keys(".")
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/usr/local/lib/python2.7/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python2.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 <textarea class="form-control file-editor-textarea js-blob-contents js-code-textarea " name="gist[contents][][value]"> is not reachable by keyboard
You can use this locator:
.find_element(By.CLASS_NAME, "CodeMirror-lines")
And also use ActionChains.
First you need following import:
from selenium.webdriver import ActionChains
Try the bellow code:
driver.get("https://gist.github.com/")
driver.find_element(By.NAME, "gist[description]").click()
driver.find_element(By.NAME, "gist[description]").send_keys("GIST DESCRIPTION")
driver.find_element(By.NAME, "gist[contents][][name]").send_keys("file.md")
#HERE
el = driver.find_element(By.CLASS_NAME, "CodeMirror-lines")
ActionChains(driver).move_to_element(el).click(el).send_keys('Description file').perform()