Python selenium:等到元素可点击 - 不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28110008/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Python selenium: wait until element is clickable - not working
提问by Storm
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()
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.
硒点击按钮,但没有任何反应。(也使用 send_Keys(Keys.Return))该应用程序是用 GXT 开发的,我认为按钮后面有很多 javascript。是否有可能等到事件加载器准备就绪?在点击之前等待解决问题,但不是自动化测试的解决方案。
回答by Helping Hands
Correct syntax for explicit wait in python is :
python中显式等待的正确语法是:
element = WebDriverWait(driver, 20).until(
EC.presence_of_element_located((By.ID, "myElement")))
Better that After above you do : element.click();
更好的是在上面你做: element.click();
So in your case :
所以在你的情况下:
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();
Better you follow it. Also share your whole code so I can correct it. Your just 1 line code doing little confuse.
最好遵循它。还分享您的整个代码,以便我可以更正它。你只是 1 行代码做一点混淆。
回答by barbudito
I had also that problem... Web apps have views over views and Appium sometimes gets wrong.
我也遇到了这个问题... Web 应用程序对视图有视图,而 Appium 有时会出错。
This worked for me:
这对我有用:
x = webElement.location['x'] + (webElement.size['width']/2)
y = webElement.location['y'] + (webElement.size['height']/2)
print("x: "+x+" - y: "+y)
//I have setted a 200 milli duration for the click...
//I use tap just for Android... If is iOS for me it works better touchAction
driver.tap([(x,y)], 200)
Edit:
编辑:
I misunderstood your question... Sorry... Maybe modifying your Xpath to: (don't know if this will work at a web app)
我误解了你的问题......对不起......也许将你的Xpath修改为:(不知道这是否适用于网络应用程序)
xpath = "//whatever_goes_here[@clickable='true']"