Text field "Element not interactable" no matter what
Question:
I’m trying to automate screenshots from the VAT check website. Example CSV file with three columns: 1st Client Name, 2nd Country Code and 3rd VAT number. The code is able to choose the country from the dropdown, but not able to enter the VAT number into the text field (Element not interactable) WebDriverWait does not help.
import csv
import datetime
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
with open('data.csv', 'r') as file:
reader = csv.reader(file)
data = list(reader)
client_name = data[1][0]
country = data[1][1]
vat_number = data[1][2]
driver = webdriver.Chrome()
driver.get('https://ec.europa.eu/taxation_customs/vies/#/vat-validation')
dropdown = Select(driver.find_element(By.XPATH,'//select[@id="select-country"]'))
dropdown.select_by_value(country)
driver.implicitly_wait(5)
vat_field = driver.find_element(By.XPATH,'//*[@id="vat-validation-form"]').send_keys(vat_number)
submit_button = driver.find_element_by_id('submit')
submit_button.click()
now = datetime.datetime.now()
date_string = now.strftime('%Y-%m-%d_%H-%M-%S')
filename = f'{date_string}_{client_name}.png'
driver.save_screenshot(filename)
driver.quit()
Any suggestions are appreciated
Answers:
The XPath provided doesn’t identify the INPUT element. It is identifying the FORM element. That’s why it throws the ElementNotInteractableException
.
Try the XPath below which identifies the INPUT element.
//input[@formcontrolname="vatNumber"]
Ideally it should be
driver.find_element(By.XPATH,'//input[@formcontrolname="vatNumber"]').send_keys(vat_number)
Update:
Use WebDriverWait() and wait for element to be clickable.
driver.get("https://ec.europa.eu/taxation_customs/vies/#/vat-validation")
dropdown = Select(WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,'//select[@id="select-country"]'))))
dropdown.select_by_value("BE")
vatNumber=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,'//input[@formcontrolname="vatNumber"]')))
vatNumber.click()
vatNumber.send_keys("VAT0000000000001")
you need to import below libraries.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
Browser snapshot:
I’m trying to automate screenshots from the VAT check website. Example CSV file with three columns: 1st Client Name, 2nd Country Code and 3rd VAT number. The code is able to choose the country from the dropdown, but not able to enter the VAT number into the text field (Element not interactable) WebDriverWait does not help.
import csv
import datetime
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
with open('data.csv', 'r') as file:
reader = csv.reader(file)
data = list(reader)
client_name = data[1][0]
country = data[1][1]
vat_number = data[1][2]
driver = webdriver.Chrome()
driver.get('https://ec.europa.eu/taxation_customs/vies/#/vat-validation')
dropdown = Select(driver.find_element(By.XPATH,'//select[@id="select-country"]'))
dropdown.select_by_value(country)
driver.implicitly_wait(5)
vat_field = driver.find_element(By.XPATH,'//*[@id="vat-validation-form"]').send_keys(vat_number)
submit_button = driver.find_element_by_id('submit')
submit_button.click()
now = datetime.datetime.now()
date_string = now.strftime('%Y-%m-%d_%H-%M-%S')
filename = f'{date_string}_{client_name}.png'
driver.save_screenshot(filename)
driver.quit()
Any suggestions are appreciated
The XPath provided doesn’t identify the INPUT element. It is identifying the FORM element. That’s why it throws the ElementNotInteractableException
.
Try the XPath below which identifies the INPUT element.
//input[@formcontrolname="vatNumber"]
Ideally it should be
driver.find_element(By.XPATH,'//input[@formcontrolname="vatNumber"]').send_keys(vat_number)
Update:
Use WebDriverWait() and wait for element to be clickable.
driver.get("https://ec.europa.eu/taxation_customs/vies/#/vat-validation")
dropdown = Select(WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,'//select[@id="select-country"]'))))
dropdown.select_by_value("BE")
vatNumber=WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,'//input[@formcontrolname="vatNumber"]')))
vatNumber.click()
vatNumber.send_keys("VAT0000000000001")
you need to import below libraries.
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
Browser snapshot: