Python Selenium正在处理一个不支持cli的元素

2024-10-02 20:33:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个弹出窗口无法关闭的问题。我曾尝试使用try/except来捕捉任何错误,但不知何故找到了元素并单击了close按钮,但该元素实际上并未从页面中消失。下面是我尝试过的代码,但我相信有一个更有效的方法来处理它

def isElementPresent():
    try:
        close_button = find_element_by_xpath(".//*[@class='x-close']")
        if close_button == "Some_Element":
            close_button.click()
    except:
        print('No Such Element')
        return False
    return True

elementSwitch = isElementPresent()

while elementSwitch == True:
    run = isElementPresent()

如有任何建议,我们将不胜感激


Tags: 代码true元素closereturn错误button页面