Python selenium:等到元素可点击 - 不工作

Sto*_*orm 24 python selenium webdriver click selenium-webdriver

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

driver.wait.until(ExpectedCondition.element_to_be_clickable((By.XPATH, "myXpath"))).click()
Run Code Online (Sandbox Code Playgroud)

selenium点击按钮,但没有任何反应.(还有send_Keys(Keys.Return))应用程序是用GXT开发的,我的事情是按钮背后有很多javascript.是否有可能等到事件加载器准备好了?在点击之前等待解决问题,但不是自动化测试的解决方案.

Hel*_*nds 51

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

 element = WebDriverWait(driver, 20).until(
 EC.presence_of_element_located((By.ID, "myElement")))
Run Code Online (Sandbox Code Playgroud)

更好的是在上面你做了: 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();
Run Code Online (Sandbox Code Playgroud)

你更好地遵循它.也分享你的整个代码,以便我能纠正它.你的1行代码很少混淆.

  • 你能想象 `WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "myXpath"))).click()` 会给我带来同样的错误吗?顺便说一句,你注意到分号了吗? (2认同)

bar*_*ito 5

我也遇到了这个问题... Web 应用程序对视图有视图,而 Appium 有时会出错。

这对我有用:

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)
Run Code Online (Sandbox Code Playgroud)

编辑

我误解了你的问题......对不起......也许将你的Xpath修改为:(不知道这是否适用于网络应用程序)

xpath = "//whatever_goes_here[@clickable='true']"
Run Code Online (Sandbox Code Playgroud)