0

My requirement is to check the quanity added to the cart matches to 1 in the Test class.

I have used the below xpath, but this throws 'NoSuchElementException'

Could you please help me locate the Element and later use the attribute value and verify if it matches to 1.

I have created a Page -

public class CartPage extends 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;

Later in the Test Class, I want to verify the quantity is 1.

    String funnyCowQty = cart.funnyCowCart.getAttribute("value");
    
    softAssert.assertTrue(funnyCowQty == "1","Funny Cow Quantity mismatch");

enter image description here

Divya
  • 59
  • 10
  • 1
    Try `contains(.,\"Funny Cow\")` without the trailing space or even `contains(translate(normalize-space(.), ' ', ''),\"FunnyCow\")` – LMC Aug 13 '21 at 17:15

1 Answers1

0

Thank you @lmc I was able to get the value of the attribute I was looking for

In the Page class I used the below xpath to locate the element @FindBy(xpath="//div[contains(.,"Funny Cow")]/p/a") public WebElement funnyCowBuy;

And in the Test class I used the below to extract the value - This gave me the quantity String fluffyBunnyQty = cart.fluffyBunnyCart.getAttribute("value"); XPath: Get parent node from child node

Divya
  • 59
  • 10