Java 为在页面工厂模型+;硒爪哇

Java 为在页面工厂模型+;硒爪哇,java,selenium,testing,xpath,automation,Java,Selenium,Testing,Xpath,Automation,我正在研究selenium页面工厂模型。我需要以这样一种方式概括xpath,它应该根据用户需求进行匹配 假设我有以下xpath @FindBy(xpath = "(//div[@class='del-hours' and contains(.,'Store #50')]//..//..//..//..//i)[2]") WebElement selectStore; 我需要根据用户输入,将此xpath用于Store#44或Store#100或任何其他对象 有了常规的findElementBy老

我正在研究selenium页面工厂模型。我需要以这样一种方式概括xpath,它应该根据用户需求进行匹配

假设我有以下xpath

@FindBy(xpath = "(//div[@class='del-hours' and contains(.,'Store #50')]//..//..//..//..//i)[2]")
WebElement selectStore;
我需要根据用户输入,将此xpath用于Store#44或Store#100或任何其他对象

有了常规的findElementBy老方法,我就能实现这一点。但我想知道,有了页面工厂的概念,我们能做到这一点吗


谢谢

我的一个项目也有类似的用例。以下是我用过的:

public RadioElement getTemplates(String id) {
            return createBaseElement(By.id("templateId")).createRadioElement(By.xpath("//input[contains(@value,'1')]"));
        }
在上述示例中: 1. ElementFactory.createBaseElement(By.id(“lia templateId”))//这是帮助定位其子元素的父类,也是最好的情况之一。Use也可以对您的用例使用类似的方法,传递具有div/id/classname的父级的定位器

2。createRadioElement(By.xpath(//input[contains(@value,'1')])))//在这里传递子类xpath详细信息我根据用户输入调用以动态方式从函数传递值

对于您的情况,您必须做一些类似的更改:

public RadioElement getTemplates(String id) {
    @FindBy(xpath = "(//div[@class='del-hours' and contains(.,'Store #id')]//..//..//..//..//i)[2]")
    WebElement selectStore;
}
尝试修改路径,因为路径似乎不合适,您可以使用
(By.xpath(“//div[contains(@class,'del-hours')])
It;这是可能的,但不是现成的。见这个问题: