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()
Related
I've error in Python Selenium. I'm trying to download all songs with Selenium, but there is some error. Here is code:
from selenium import webdriver
import time
driver = webdriver.Chrome('/home/tigran/Documents/chromedriver/chromedriver')
url = 'https://sefon.pro/genres/shanson/top/'
driver.get(url)
songs = driver.find_elements_by_xpath('/html/body/div[2]/div[2]/div[1]/div[3]/div/div[3]/div[2]/a')
for song in songs:
song.click()
time.sleep(5)
driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div[1]/div[2]/div/div[3]/div[1]/a[2]').click()
time.sleep(8)
driver.get(url)
time.sleep(5)
And here is error:
Traceback (most recent call last):
File "test.py", line 13, in <module>
song.click()
File "/home/tigran/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "/home/tigran/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/home/tigran/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/tigran/.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.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=90.0.4430.72)
Any ideas why error comes?
Before your loop try to add try:
Sometimes the document is not attached, so it gives an error
Here's link selenium while loop not working. You need to locate elements in loop.
Final code:
from selenium import webdriver
import time
driver = webdriver.Chrome('/home/tigran/Documents/chromedriver/chromedriver')
url = 'https://sefon.pro/genres/shanson/top/'
driver.get(url)
size = len(driver.find_elements_by_xpath('/html/body/div[2]/div[2]/div[1]/div[3]/div/div[3]/div[2]/a'))
for i in range(0, size):
songs = driver.find_elements_by_xpath('/html/body/div[2]/div[2]/div[1]/div[3]/div/div[3]/div[2]/a')
songs[i].click()
time.sleep(5)
driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[1]/div[1]/div[2]/div/div[3]/div[1]/a[2]').click()
time.sleep(8)
driver.execute_script("window.history.go(-1)")
time.sleep(5)
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
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"]')
I am using a Selenium module in Python to log into Quora. It works fine for Facebook, but I am getting an error on the send_keys('my_email') line while trying it on Quora:
I am using the following script.
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
driver = webdriver.Firefox()
driver.get('http://www.quora.com/')
time.sleep(60)
username = driver.find_element_by_name('email')
time.sleep(60)
username.send_keys('my_email')
time.sleep(60)
password = driver.find_element_by_name('password')
time.sleep(60)
password.send_keys('my_password')
time.sleep(60)
password.send_keys(Keys.RETURN)
driver.close
Sleep time is not a problem here, because I tried executing a script line by line using the Python shell.
Error:
Traceback (most recent call last): File "", line 1, in
password.send_keys('my_password') File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 293, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': typing}) File
"C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 370, in _execute
return self._parent.execute(command, params) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 173, in execute
self.error_handler.check_response(response) File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 164, in check_response
raise exception_class(message, screen, stacktrace) ElementNotVisibleException: Message: u'Element is not currently
visible and so may not be interacted with' ; Stacktrace:
at fxdriver.preconditions.visible (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:8791:5)
at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:11438:1)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:11455:11)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:11460:7)
at DelayedCommand.prototype.execute/< (file:///c:/users/siddhesh/appdata/local/temp/tmpgwft3s/extensions/fxdriver#googlecode.com/components/command_processor.js:11402:5)
The problem is that there are multiple inputs with name="email".
You need the one in the "Regular Login" section:
form = driver.find_element_by_class_name('regular_login')
username = form.find_element_by_name('email')
username.send_keys('my_email')
password = form.find_element_by_name('password')
password.send_keys('my_password')