Company logo
  • Jobs
  • Bootcamp
  • About Us
  • For professionals
    • Home
    • Jobs
    • Courses and challenges
    • Questions
    • Teachers
    • Bootcamp
  • For business
    • Home
    • Our process
    • Plans
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Calculator

0

84
Views
Selenium set value to input field that is not visible

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 (tabindex=-1). 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.

7 months ago · Juan Pablo Isaza
1 answers
Answer question

0

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[0].value='"+value+"'", input_field)
7 months ago · Juan Pablo Isaza Report
Answer question
Find remote jobs