microsoft / WinAppDriver

Windows Application Driver
MIT License
3.66k stars 1.4k forks source link

An element command could not be completed because the element is not pointer- or keyboard interactable. when using for loop #1862

Open noobProgrammer112 opened 1 year ago

noobProgrammer112 commented 1 year ago

I am using python, appium, winappdriver with selenium3 In a word document, i am finding elements using name, 2 elements on each page of my word document. these elements are textboxes, i want to visit all these textboxes and change their values. When i use for loop to iterate over the list of elements, i am getting following exception on 3rd element(textbox) (on the 2nd page) Traceback (most recent call last): File "C:\Users\syedm\Desktop\new\main.py", line 20, in textBoxes[h].click() File "C:\Users\syedm\Desktop\new\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click self._execute(Command.CLICK_ELEMENT) File "C:\Users\syedm\Desktop\new\venv\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute return self._parent.execute(command, params) File "C:\Users\syedm\Desktop\new\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\syedm\Desktop\new\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 31, in check_response raise wde File "C:\Users\syedm\Desktop\new\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 31, in check_response raise wde File "C:\Users\syedm\Desktop\new\venv\lib\site-packages\appium\webdriver\errorhandler.py", line 26, in check_response super().check_response(response) File "C:\Users\syedm\Desktop\new\venv\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) selenium.common.exceptions.WebDriverException: Message: An element command could not be completed because the element is not pointer- or keyboard interactable.

but if i directly reference it as textBoxes[2] ( 3rd textbox), instead of textBoxes[i] in the for loop, i can reach it and successfully change the value in the textbox.

Following is my code: from appium import webdriver from selenium.webdriver.common.keys import Keys from time import sleep desired_caps = {} desired_caps['app'] = 'C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE' desired_caps['platformName'] = "Windows" desired_caps['appArguments'] = '/q'

driver = webdriver.Remote("http://127.0.0.1:4723", desired_caps)

sleep(2) driver.find_element_by_name('Some doc name').click() sleep(2) textBoxes = driver.find_elements_by_xpath("//*[@LocalizedControlType='textbox']") print(len(textBoxes))

this for loop is causing the problem

for h in range(0, len(textBoxes)): sleep(5) textBoxes[h].click() textBoxes[h].send_keys(Keys.CONTROL+'a') textBoxes[h].send_keys(Keys.BACK_SPACE) is_nameBox=not(is_nameBox) sleep(2) textBoxes[h].send_keys('Some data') sleep(2)

I am beginner to this Will appreciate a lot if i get any help

liljohnak commented 1 year ago

From the stack one of your text boxes is not clickable. I am using the c# driver, but I believe something like this should work. If it is a readonly text box consider using the isKeyboardFocusable property. (These can be found by using inspect.exe.)

for h in range(0, len(textBoxes)):
sleep(5)
if textBoxes[h].get_attribute('offscreen') == 'True': continue
textBoxes[h].click()
textBoxes[h].send_keys(Keys.CONTROL+'a')
textBoxes[h].send_keys(Keys.BACK_SPACE)
is_nameBox=not(is_nameBox)
sleep(2)
textBoxes[h].send_keys('Some data')
sleep(2)