Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
127 views
in Technique[技术] by (71.8m points)

python - click function not rendering the page

I am trying to retrieve PNR details but the click function runs into a timeout exception. What could be the possible issue that causes this timeout?

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.common.keys import Keys

driver = webdriver.Chrome(executable_path=r'D:/Chrome driver/chromedriver.exe')

driver.get("link")

WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='PNRId']"))).send_keys("QPDYUX")

WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='GstRetrievePageInteraction']"))).click()


WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.CLASS_NAME, "gst-invoice-list.list-inline")))

elements = driver.find_elements(By.CLASS_NAME, "gst-invoice-list.list-inline")

It gives following error TimeoutException: timeout: Timed out receiving message from renderer: 300.000 (Session info: chrome=87.0.4280.141)

How can I move forward with this?

question from:https://stackoverflow.com/questions/65857378/click-function-not-rendering-the-page

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Try adding the following to stop the website from knowing it's a bot.

from selenium.webdriver.chrome.options import Options
options.add_argument('--disable-blink-features=AutomationControlled')    
driver = webdriver.Chrome(executable_path=r'D:/Chrome driver/chromedriver.exe',options=options)

Now for the following:

wait = WebDriverWait(driver, 10)
driver.get("link")
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='PNRId']"))).send_keys("QPDYUX")
wait.until(EC.element_to_be_clickable((By.XPATH, "//input[@id='GstRetrievePageInteraction']"))).click()
elements = wait.until(EC.presence_of_all_elements_located((By.CSS_SELECTOR, ".gst-invoice-list.list-inline")))
for elem in elements:
    print(elem.text)

Outputs:

GST Invoice No. View/Print
MH1202106AB57221 View Invoice Print Invoice
MH2202106AB78553 View Invoice Print Invoice

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...