尝试自动化流程时元素不可交互错误

Element not Interactable Error when trying to automate a process

我正在尝试发送一个值并单击按钮以检索某些 pdf,但我收到一个错误消息,指出元素不可交互。我尝试使用不同的选择器,但我遇到了同样的错误。 下面是我的代码:

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("link")

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('pnr')

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

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

要将字符序列发送到 PNR 字段,您可以使用以下 :

  • 使用CSS_SELECTOR:

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

最好发送你需要诱导的文字WebDriverWait for the and you can use the following :

  • 使用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")
    
  • 注意:您必须添加以下导入:

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
  • 浏览器快照: