gpt4 book ai didi

java - @FindBy 与 Arquillian Graphite 烯

转载 作者:行者123 更新时间:2023-12-02 07:04:21 26 4
gpt4 key购买 nike

实际上我想获取一个带有 @FindBy 的元素,该元素用于页面对象模式。

我有 2 个类,第一个是名为 TestPage 的页面对象,第二个名为 PageSaveTest (我的测试在其中进行并调用 测试页)。

我还尝试将 @FindByxpathid 一起使用。

>>这是我的测试页

import java.util.List;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class TestPage {

// get autocomplete input
@FindBy(css = "input[id*='supplierOps_input']")
private WebElement autocompleteSupplierOps;

// getter
public WebElement getAutocompleteSupplierOps() {
return autocompleteSupplierOps;
}

}

>> 这是我的 PageSaveTest

// How i "inject" my TestPage
@Page
TestPage testpage;

[...]
// My test
WebElement autocomplete = testpage.getAutocompleteSupplierOps();

String keys = "OP";
autocomplete.sendKeys(keys); // >>>>>>> Error throwed here !
List<WebElement> listSugg = testpage.getSuggestionsSupplierOps();

错误消息:

org.openqa.selenium.NoSuchElementException : Returned node was not an HTML element.

我的想法:

我认为问题来自于@FindBy。但我用this example构建我的测试页和我的测试和 this one too .

问题:有人可以向我解释一下 @FindBy 的工作原理以及如何在我的示例中使用吗?关于 Graphite 烯的文档确实很差。

<小时/>

编辑:

我已经在TestPage(上面)中修改了我的getter,我尝试了简单地打印id属性值,例如

public WebElement getAutocompleteSupplierOps() {
System.out.println(">>>> "+autocompleteSupplierOps.getAttribute("id"));
return autocompleteSupplierOps;
}

但仍然是同样的错误,@FindBy 搞砸了。

Another @FindBy spec添加到本期。

<小时/>

更新:

我已经修复了我的选择器,但实际上驱动程序 session 存在问题,例如:

             page2.getAutocompleteSupplierOps();
PAGE 1 ----------------------------------> PAGE 2
driver id:1 ----------------------------------> driver id:2
driver.showPageSource() is empty
return no element found <---------------------- driver.findElement() -> not found

我使用了 3 种不同的方法,@FindBy@Drone WebDriver 以及最后 @Lukas Fryc 向我建议的方法。

最佳答案

您可以尝试直接使用驱动程序,而不是使用 @FindBy 注入(inject) WebElement:

WebDriver driver = GrapheneContext.getProxy(); // this will be removed in Alpha5 version, use `@Drone WebDriver` instead
WebElement autocompleteSupplierOps =
driver.findElement(By.css("input[id*='supplierOps_input']"));

但它应该为您提供与 @FindBy 相同的结果 - 但它会检查问题是否不是由注入(inject)引起的,而是出现了其他问题。

您可能使用了错误的 CSS 选择器 - CSS 选择器的支持取决于所使用的浏览器及其版本。

您尝试查找的节点不一定位于页面中,您可能需要使用等待 API 或请求防护等待它出现。

最佳实践是在开发中使用远程可重用 session 和真实浏览器 - 它可以快速揭示原因。

关于java - @FindBy 与 Arquillian Graphite 烯,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16274596/

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