Paw*_*yal 3 selenium selenium-webdriver
Webdriverjs显然有一个内置的方法,允许你等待一个元素.
var saveButton = driver.wait(until.elementLocated(By.xpath("//div[text() = 'Save']")), 5000);
driver.wait(until.elementIsVisible(saveButton), 5000).click();
Run Code Online (Sandbox Code Playgroud)
使用此方法会导致错误"ReferenceError:until not defined".为什么这种方法不起作用?
我阅读了webdriverjs文档,其中给出的示例缺少'webdriver'关键字.
var saveButton = driver.wait(webdriver.until.elementLocated(webdriver.By.xpath("//div[text() = 'Save']")), 5000);
driver.wait(until.elementIsVisible(saveButton), 5000).click();
Run Code Online (Sandbox Code Playgroud)
在'until'和'By'之前添加'webdriver'关键字可以解决问题.
最常见的最佳做法是在需要webdriver之后立即要求webdriver.By并webdriver.until在文件顶部.
那么你不必webdriver.By在测试中做,你可以做driver(By.css())
我不确定您使用的语言绑定。使用 Java 绑定,在 Selenium 3.x 版本中until必须附带ExpectedConditions
因此,要在元素上应用 ExplicitWait 并单击它,您的代码必须如下所示:
WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement element = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[text() = 'Save']")));
element.click();
Run Code Online (Sandbox Code Playgroud)
如果这可以解决您的问题,请告诉我。
| 归档时间: |
|
| 查看次数: |
1600 次 |
| 最近记录: |