I am trying to set value to an input field via selenium-python but the problem is that it's not visible. So it throws "Element not interactable" error.
This is because the input field is part of an
"li", that has a role of "tab" and at any point only one
"li" can be active
(tabindex=0), while the remaining are not visible
I am writing an automation script that requires setting the input values in one "tab", and then doing something on the other "tab", but when switching to the other tab, that tab stays active and on the second run the previous tab is no longer active, hence I can't set the value anymore.
I tried deleting all cookies and local and session storage but the change in tab visibility is persistent. Is there any way of doing what I want to do?
Thanks in advance.
I suggest adding an additional step to your scenario:
Activate the tab for the particular input before setting the value.
From your description, you just have to click on the tab.
So your script might look like this:
from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By def fill_input_filed_a(a_value): driver.find_element(tab_for_input_a).click() input = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(input_filed_a)) input.clear() input.send_keys(a_value) def fill_input_filed_b(b_value): driver.find_element(tab_for_input_b).click() input = WebDriverWait(driver, 10).until(EC.visibility_of_element_located(input_filed_b)) input.clear() input.send_keys(b_value) # then invoke methods in test fill_input_filed_a('value1') fill_input_filed_b('value2')
If you still want to work with hidden field, try
Set value to input field that is not visible
It's possible with JS, but this might not work, since some events might not be fired when you just set the value with java-script.
input_field = driver.find_element(hidden_input_filed) driver.execute_script("arguments.value='"+value+"'", input_field)