Reputation: 283
I am trying to fill the form on (https://all-access.wax.io). When I am using Javascript
document.getElementsByName("userName")[0].value = "Hello"
, then I am able to write text to a form. However, when I am using same concept in selenuim
driver.find_element_by_name("userName").send_keys("Hello")
, then I am getting:
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
When I am executing:
self.driver.find_element_by_name("userName")[1].send_keys("Hello")
this leads to:
TypeError: 'WebElement' object is not subscriptable
I have also tried to wait until content is loaded, as well as use XPath and other selectors. I guess I am doing a simple mistake, but I can`t resolve it for several hours already.
Code to reproduce a problem:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get('https://all-access.wax.io')
browser.find_element_by_name("userName")[1].send_keys("hello")
print()
Upvotes: 1
Views: 844
Reputation: 9969
browser.find_element_by_xpath("(//input[@name='userName'])[2]").send_keys("hello")
You want to send_keys to the second input tag and not the first.
Upvotes: 2
Reputation: 4212
The approach with only name
attribute did not work for me because when you are trying to access with [1] there are still two elements, so the locator is not unique.
So, I used the parent pannels visible-desktop-only-flex
class and also added explicit wait.
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.wait import WebDriverWait
browser = webdriver.Chrome(executable_path='/snap/bin/chromium.chromedriver')
browser.get('https://all-access.wax.io')
wait = WebDriverWait(browser, 15)
wait.until(EC.element_to_be_clickable((By.XPATH, "//div[@class='pannels visible-desktop-only-flex']//input[@name='userName']")))
browser.find_element_by_xpath("//div[@class='pannels visible-desktop-only-flex']//input[@name='userName']").send_keys("hello")
Upvotes: 1
Reputation: 19929
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
browser = webdriver.Chrome()
browser.get('https://all-access.wax.io')
browser.find_element_by_name("userName").send_keys("hello")
print()
you are using find_element which returns a webelement and not array , use find_elements or remove the index
Upvotes: 1