硒点击接受风险并继续 [英] selenium click on Accept the risk and continue

查看:95
本文介绍了硒点击接受风险并继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用 selenium 加载了以下 drive.page_source :

I have loaded the following drive.page_source using selenium:

      <div id="advancedPanelContainer">
        <div id="badCertAdvancedPanel" class="advanced-panel">
          <p id="badCertTechnicalInfo"></p>
          <a id="viewCertificate" href="javascript:void(0)">View Certificate</a>
          <div id="advancedPanelButtonContainer" class="button-container">
            <button id="advancedPanelReturnButton" class="primary" data-telemetry-id="return_button_adv">Go Back (Recommended)</button>
            <button class="primary try-again">Try Again</button>
            <div class="exceptionDialogButtonContainer">
              <button id="exceptionDialogButton" data-telemetry-id="exception_button">Accept the Risk and Continue</button>
            </div>
          </div>
        </div>

我试图单击按钮接受风险并继续.我尝试了

I am trying to click on the button Accept the Risk and Continue .I tried with

driver.find_element_by_xpath('.//button[@id="exceptionDialogButton"]')

,但是在未呈现 driver.page_source 的地方,它不会返回错误.

but it returns no error where the driver.page_source is not rendered.

呈现的中间页面包含安全证书和安全按钮.

An intermediate rendered page contains security certificates and security button.

如何正确找到该元素?

我尝试单击该按钮,但建议的解决方案未成功

I tried to click the button but no success with the proposed solutions

我正在尝试使用以下 selenium 选项,配置文件和功能访问此链接

I am trying to access this link with following selenium options,profile and capabilities

url='http://kerix-export.net/en/exporter/Banque-Centrale-Populaire_MA5000212955d58c725.html'

def selenium_profile(args):
    #
    proxy_ip,proxy_port,username,password=args
    #
    proxy={"http": "http://"+username+":"+password+"@"+str(proxy_ip)+":"+str(proxy_port),
    "https": "http://"+username+":"+password+"@"+str(proxy_ip)+":"+str(proxy_port)}
    #SELENIUM ENTRIES
    cap = DesiredCapabilities().FIREFOX
    cap["marionette"] = True
    cap['acceptInsecureCerts'] = True
    #capabilities['acceptSslCerts'] = False
    binary = FirefoxBinary('/usr/bin/firefox')
    ##
    options = Options()
    options.add_argument('--headless')
    options.add_argument('--no-sandbox')
    options.add_argument('--load-images=no')
    options.add_argument("window-size=1400,600")
    options.add_argument('--ignore-certificate-errors')
    options.add_argument('--proxy-server=%s' % proxy)
    ##
    profile = webdriver.FirefoxProfile()
    profile.accept_untrusted_certs = True
    #profile.set_preference("general.useragent.override", "[user-agent string]")
    profile.set_preference("general.useragent.override", 
        "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:63.0) Gecko/20100101 Firefox/63.0")
    #
    return profile,options,cap,binary

与最终通话:

profile,options,cap,binary=selenium_profile(args)
driver,options,args,df=selenium_request(profile,options,cap,binary,url,df,args)

我认为按照TLS协议可以解决该问题

I think the issue can be solved following the TLS protocol

<p>This website might not support the TLS 1.2 protocol, which is the minimum version supported by Firefox. Enabling TLS 1.0 and TLS 1.1 might allow this connection to succeed.</p>

推荐答案

如果已经有元素ID,则不应寻找更困难的方法.试试这个:

You should not look for a harder ways if there is already element ID. Try this:

from selenium.webdriver.support.wait import WebDriverWait

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((SelectBy.ID, "exceptionDialogButton")))
driver.driver.find_element_by_id("exceptionDialogButton").click()

也可以尝试使用 exception_button 作为定位器.也可以尝试使用CSS选择器:button [data-telemetry-id = exception_button]

Try also exception_button as a locator. Also try css selector: button[data-telemetry-id=exception_button]

它看起来像这样:

from selenium.webdriver.support.wait import WebDriverWait

wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((SelectBy.CSS_SELECTOR, "button[data-telemetry-id=exception_button]")))
driver.driver.find_elements_by_css_selector("button[data-telemetry-id=exception_button]").click()

这篇关于硒点击接受风险并继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆