Python Selenium:等到元素可单击-不起作用 [英] Python selenium: wait until element is clickable - not working

查看:830
本文介绍了Python Selenium:等到元素可单击-不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将测试一个网络应用程序.我的表格中有一个按钮可以选择所有条目. 我尝试过:

I will test a web-app. there is a button available in my table to select all entries. I've tried:

driver.wait.until(ExpectedCondition.element_to_be_clickable((By.XPATH, "myXpath"))).click()

硒单击按钮,但是什么也没有发生. (也与send_Keys(Keys.Return)一起使用),该应用程序是使用GXT开发的,我觉得按钮后面有很多JavaScript.是否有可能等到事件加载器准备就绪?等待点击解决问题,但不是自动测试的解决方案.

selenium clicks on the button, but nothing happens. (also with send_Keys(Keys.Return)) the application is developed with GXT, I thing that there is much javascript behind the button. Is there is possibility to wait until a eventloader is ready? waiting before a click solves the problem, but not a solution for automated testing.

推荐答案

在python中显式等待的正确语法是:

Correct syntax for explicit wait in python is :

 element = WebDriverWait(driver, 20).until(
 EC.presence_of_element_located((By.ID, "myElement")))

最好在完成上述操作之后: element.click();

Better that After above you do : element.click();

所以在您的情况下:

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

element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, "myXpath")))

element.click();

更好地遵循它.同时分享您的整个代码,以便我纠正.您只需1行代码就不会造成混乱.

Better you follow it. Also share your whole code so I can correct it. Your just 1 line code doing little confuse.

这篇关于Python Selenium:等到元素可单击-不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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