简体   繁体   中英

input element overshadows the click button - Python, selenium

I am trying to send a PNR and then click on the submit button. The PNR gets correctly filled in but the submit button is not getting clicked. So I commented on the send_key() line and checked if the submit button is getting clicked and it gets clicked. But when I send the PNR value and subsequently click the submit button it doesn't work.

Below is the snapshot of the same: 当 send_keys() 被注释结果

and below is the code:

import time
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.common.exceptions import NoSuchElementException

driver = webdriver.Chrome(executable_path=r'D:/Chrome driver/chromedriver.exe')
driver.get("https://www.spicejet.com/")

time.sleep(10)

driver.execute_script("arguments[0].click();", WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, '//*[@id="main-container"]/div/div[1]/div[5]/div[2]/a[6]/div/div[2]/div[1]'))))

#WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//input[@placeholder='PNR']"))).send_keys("AGQR8U")

WebDriverWait(driver, 50).until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[16]/div/div/div/div[3]/div[1]/div'))).click()

Can anyone help me with how to make the submit button work?

There is a workaround that keeps on clicking in an infinite loop until the next popup or screen is displayed.

Code:

driver.maximize_window()
wait = WebDriverWait(driver, 30)

driver.get("https://www.spicejet.com/")

button = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[text()='GST Invoice']")))
driver.execute_script("arguments[0].click();", button)
wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "input[placeholder='PNR']"))).send_keys('AGQR8U')
submit_btn = wait.until(EC.element_to_be_clickable((By.XPATH, "//div[text()='Submit']")))
while True:
    submit_btn.click()
    try:
        if driver.find_element(By.XPATH, "//div[text()='PNR']").is_displayed():
            print('PNR is displayed')
            break
        else:
            print('PNR is not displayed yet. Keep retrying submit click')
    except:
        pass

Import:

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

Output:

PNR is displayed

在此处输入图像描述

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