How to use the .inside() method of the Target class? #3327
Unanswered
maciejfec2i
asked this question in
Q&A
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hello,
I am trying to understand how the .inside() method of the Target class works. I am attempting to use it to locate an element nested within another element, but this does not seem to be working and I am unsure whether I am using it wrong or if it's an actual issue.
To give an example, I am trying to locate the 'Add to cart' button on the 'Sauce Labs Fleece Jacket' item card
I have a Button class with a WITH_TEXT Target variable which uses an xpath locator to locate the button
And I have an ItemCard class with a FOR_ITEM_WITH_NAME Target variable which again uses an xpath to locate the correct item card based on the item name
I also have a AddToCart Task class which takes in a list of item names and attempts to click on the 'Add to cart' button for each item
Here I am attempting to use the .inside() method to try and locate the 'Add to cart' button inside of the item card that has the desired item name
Click.on(Button.WITH_TEXT.of("Add to cart").inside(ItemCard.FOR_ITEM_WITH_NAME.of(itemName)))
I was expecting this to lead to an end locator of something along the lines of
//div[@class='inventory_item_description'][contains(., 'Sauce Labs Fleece Jacket')]//button[. = 'Add to cart']
Or
//div[@class='inventory_item_description'][contains(., 'Sauce Labs Fleece Jacket')]//descendant::button[. = 'Add to cart']
But the .inside() method in this case does not seem to do anything and only the initial Target locator is used which in this case is the locator for the 'Add to cart' button, meaning that instead of clicking on the 'Add to cart' button nested inside the correct item card, the click is just performed on the first 'Add to cart' button that is found.
This is also reflected in the Serenity report which ends up saying:
Standard User clicks on 'Add to cart' button
Whereas I was expecting something along the lines of:
Standard User clicks on 'Add to cart' button nested in item card for 'Sauce Labs Fleece Jacket'
So back to the meat and potatoes, am I just completely off the mark in terms of how this is to be used? Any guidance would be greatly appreciated.
Thank you :)
Beta Was this translation helpful? Give feedback.
All reactions