不能使用Selify点击按钮(Python) [英] Not able to click button with Selenium (Python)

查看:30
本文介绍了不能使用Selify点击按钮(Python)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用Selify单击一个按钮,但每次我都收到消息说它找不到该元素。即使我把时间放在前面,也会发生这种情况。

time.sleep(5)

                #Click on download
                downloadButton = driver.find_element_by_css_selector('#downloadButton')
                time.sleep(5)
                downloadButton.click()

                #Click on close
                closeButton = driver.find_element_by_xpath('//*[@id="btnZorgAnnuleren"]')
                closeButton.click()

按钮位于框架(不是iframe)中,但我不知道如何切换到它。下面是框架源代码和页面源代码:https://www.codepile.net/pile/ZoG0REzQ。有谁能帮帮我吗?

推荐答案

如果是iFrame:

我建议您切换到这样的框架(带有明确的等待):

wait = WebDriverWait(driver, 10)
wait.until(EC.frame_to_be_available_and_switch_to_it((By.ID, "iframe ID")))

导入:

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

切换后,您可以像这样点击:

wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "#downloadButton"))).click()

并点击关闭:

 wait.until(EC.element_to_be_clickable((By.ID, "btnZorgAnnuleren"))).click()

完成后,您应该切换到默认内容,如下所示:

driver.switch_to.default_content()

这篇关于不能使用Selify点击按钮(Python)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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