我的要求是检查添加到购物车的数量是否与Test类中的1匹配。
我使用了下面的xpath,但它抛出了'NoSuchElementException‘
您能否帮助我定位元素,然后使用属性值并验证它是否与1匹配。
我创建了一个页面-
公共类CartPage扩展了BasePage{
@FindBy(xpath="//tr/td[contains(.,\" Funny Cow\")]/td[3]/input/@value") //NoSuchElementException thrown for this line
public WebElement funnyCowCart;
@FindBy(xpath="//tr/td[contains(.,\" Fluffy Bunny\")]/td[3]/input/@value")
public WebElement fluffyBunnyCart;
@FindBy(xpath="//a[@href=\"#/checkout\"]")
public WebElement checkOut;
稍后在测试类中,我想验证数量是否为1。
String funnyCowQty = cart.funnyCowCart.getAttribute("value");
softAssert.assertTrue(funnyCowQty == "1","Funny Cow Quantity mismatch");
发布于 2021-08-13 17:45:48
谢谢你@lmc,我能够得到我正在寻找的属性的值。
在Page类中,我使用下面的xpath来定位元素@FindBy(xpath="//divcontains(.,"Funny Cow")/p/a")公共WebElement funnyCowBuy;
在Test类中,我使用下面的代码提取值--这给出了数量字符串fluffyBunnyQty = cart.fluffyBunnyCart.getAttribute(" value ");XPath: Get parent node from child node
https://stackoverflow.com/questions/68775866
复制