【问题标题】:Selenium href click after inputting field输入字段后单击 Selenium href
【发布时间】:2021-04-25 12:18:55
【问题描述】:

我是 selenium 和 python 的新手,希望在这里得到一些指导。

我正在尝试输入邮政编码,然后解析显示的结果数据。我遇到的问题是,在输入邮政编码后,我似乎无法点击正确的 href id。

我正在测试的网站是:https://www.citizensbank.com/custom/RegionializationGateway.aspx?targetpage=/loans/mortgage-refinance.aspx#

我正在使用 selenium 版本 3.141.0 和 python 3.9.1

我尝试过的如下: ...

inputElement = driver.find_element_by_id('zip_input_region')
inputElement.send_keys(zip)

#Attempt 1 not working
searcher = driver.find_element_by_class_name("cta_btn")
searcher.click()

#Attempt 2 not working
element_to_click = driver.find_element_by_id("zip_submit_region")
driver.execute_script("arguments[0].click();", element_to_click)

#Attempt 3 not working
driver.find_element_by_link_text("Submit").click()

WebDriverWait(driver, 15).until(EC.url_changes(url))

...

我错过了什么?感谢您提供的任何帮助或指导。

提前致谢!

【问题讨论】:

    标签: python selenium href


    【解决方案1】:

    尝试以下等待元素可点击。还添加了选项

    options = Options()
    options.add_argument('--disable-blink-features=AutomationControlled')
    driver = webdriver.Chrome(options=options)
    wait = WebDriverWait(driver, 10)
    driver.get('https://www.citizensbank.com/custom/RegionializationGateway.aspx?targetpage=/loans/mortgage-refinance.aspx#')
    wait.until(EC.element_to_be_clickable((By.ID, "zip_input_region"))).send_keys(zip)
    wait.until(EC.element_to_be_clickable((By.ID, "zip_submit_region"))).click()
    

    导入

    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
    

    【讨论】:

    • 谢谢,你的代码得到了同样的结果。邮政编码验证,但未执行超链接。它应该带您到另一个页面以显示费率信息。我一定在这里遗漏了其他东西。再次感谢。
    • @Jon 它似乎知道这是一个机器人尝试以下更改。
    猜你喜欢
    • 1970-01-01
    • 2022-01-05
    • 1970-01-01
    • 2018-01-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多