Have the following task:
on the website of the online store
- Go to “Discounts” section
- Randomno, on the 3rd pages to choose a product, fall into the product card and check availability of the promotion and old price
- do it for 3 products (the choice of the number of goods being checked is flexible).
Actually, as I imagine:
- Main class. Initialization, transition to a page with discounts, main
- Class for a page with discounts Find all elements of goods by
XPath, choose 3 random goods and prescribe them method
click ()(random pages still miss, do everything on the first)
- Class for the product card page Here we need to check if it is in each of 3 products such elements as a promotional and old price.
To do this, I understand it, you need to use
Findelements (), which returns a sheet of elements. If in it will be
2 values, it means everything is fine. If less, it means with a commodity
Actually, I do not quite understand how to associate everything and how to register the main logic. I will be very grateful for detachable answers.
The answer is not the truth of the last instance. Just in the comments would not fit.
I would suggest another option.
Once you have found a list of WebElement, then after manipulations on the page items from the list may not be available. Then you will receive NosuchelementException. Therefore, it is better to get a list from the Discount Page, do not touch the page, open each item in a new tab, get a discount, close the tab, open another item in a new tab.
- Open Page Main
- Go to Discounts page
- Describe a discount page in such a way that List is filled all products. (by default they are 24) (
// * [@ id = "products_on_sale_pagination_contents"] / divHere are their ways)
- walk along the For-Ohm list + limit the number of your dynamic value.
- for each item Open it in the new SwitchTotab
- Initialize a new class, which describes the product page, where it is described how to get the price, action, etc.,
New Products. WAIITFORLOAD (). GetMepriceplease ()
- here you can either close the tab, or just go to the first tab. Where is the list of goods
- make the same for another element
Total you collected a list of necessary prices.
The advantages of the approach in that, do not get nosuchelementException, in addition to this items will remain in their places and will not be moved if one of them disappeared from discounts or new added.
Cons: 24 element limit. Or before initialization you need to click on “Show more 24”, “Show another 24”, “Show another 24”