简体   繁体   中英

Element not Interactable Error when trying to automate a process

I am trying to send a value and click on the button to retrieve certain pdfs but I am getting an error that element is not interactable. I tried using different selectors but I am getting the same error. Below is my code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

from selenium.webdriver.chrome.options import Options
options=Options()
prefs = {"download.default_directory" : "D:\Trvael_Test_Script\GSTInvoiceDownloads"}
options.add_experimental_option("prefs",prefs)

from selenium.webdriver.chrome.service import Service
s=Service('C:/webdrivers/chromedriver.exe')

driver = webdriver.Chrome(service=s,options=options)
driver.get("https://book.spicejet.com/")

time.sleep(10)

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="GST"]/span[1]'))).click()

time.sleep(5)

driver.switch_to.frame(driver.find_element(By.ID,'ifgstdownloadnFrame'))

time.sleep(5)


driver.find_element(By.XPATH,'//*[@id="txtpnr"]').send_keys('AGQR8U')

driver.find_element(By.XPATH,'//*[@id="btnSubmit"]').click()```

Can anyone please let me know how to make the element interactable?

To send a character sequence to the PNR field you can use the following Locator Strategy :

  • Using CSS_SELECTOR :

     driver.find_element(By.CSS_SELECTOR, "input#txtpnr").send_keys("AGQR8U")

Ideally to send the text you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy :

  • Using CSS_SELECTOR :

     driver.get("https://book.spicejet.com/") WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//span[text()='GST Invoice']"))).click() WebDriverWait(driver, 20).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"div#GSTInvoicePopUP iframe#ifgstdownloadnFrame"))) WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input#txtpnr"))).send_keys("AGQR8U")
  • Note : You have to add the following imports:

     from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
  • Browser Snapshot:

spicejet_GST

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM