gpt4 book ai didi

java - 在测试中哪里使用ajax方法?如何查看我可以在哪里使用它们?

转载 作者:行者123 更新时间:2023-12-02 09:05:29 25 4
gpt4 key购买 nike

我是自动化领域的新手,面临着 ajax 方法来单击等,但不清楚在哪里可以使用它们。现在,如果我无法点击某个元素,我会使用ajax,但是有什么方法可以在页面上看到它,我必须对特定元素使用ajax方法吗?

 public void ajaxFocus() {
JavascriptExecutor jse = (JavascriptExecutor) driver;
jse.executeScript("document.getElementById('elementid').focus();");
}


public void ajaxClick(WebElement element) {
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true)", element);
wait.until(ExpectedConditions.elementToBeClickable(element));
element.click();
}

public void ajaxClick(By by) {
wait.until(ExpectedConditions.presenceOfElementLocated(by));
wait.until(ExpectedConditions.elementToBeClickable(by));
ajaxClick(driver.findElement(by));
}

我现在有这些要测试,但不确定在哪里使用它们。目前,据我了解,当常规单击方法不起作用时,我可以使用它们。是否有任何异常(exception)情况需要我使用 ajax 方法?

最佳答案

当 native webdriver 功能不起作用时,您可以使用这些方法作为备份。 WebDriver 方法与 js 执行器方法相比,在单击之前执行一些操作,例如检查元素是否可见、可单击等。您可以在此处找到更多信息 - https://www.w3.org/TR/webdriver/#element-click而 js 命令则不然。有时我会使用 js 命令,例如元素的不透明度设置为 0 并且 webdriver 无法单击它,而 js 命令工作正常

关于java - 在测试中哪里使用ajax方法?如何查看我可以在哪里使用它们?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59847177/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com