TestProject Forum

How to specify and select products to cart in any online shopping website for webtesting

Hi,

I am trying to add products to cart in an ecommerce website with web recorder option in TestProject every time i run the automation its failing at “Add to Cart” saying that “the element not found and Timeout exception” i am not able to proceed further. the automation fails either at “Add to cart” or at “Checkout” with this same error. How can we fix this.

Thanks in advance!!

Hi sahanijuttukon, what’s up?

There are few possible reasons for this behavior,

  1. First try edit the element like in the image below,

image

To check your locators use the magnifying glass
(notice the element must be present in the page when checking a locator):

If another locator is more consistent make it your primary locator, push it to the top with the arrows next to the magnifying glass.

  1. Check for a unique attribute and search the button by that locator,

you can make your custom locator like this for example:
using Xpath //*[@attribute="value"]

For instance my locator for Amazon looks like this:
using Xpath //*[@id="add-to-cart-button"]

  1. Check your test settings, give your test more time to find the element,
    You can do it like so:

Let me know if that helped you solved the problem.

Hi, Thanks for your reply, however my issue is still not fixed.

For “ADD TO CART” i have 3 locators as below and my Automation is getting failed with below error always.

  1. XPATH=//span[. = ‘ADD TO CART’]
    TimeoutException: Timeout occurred while trying to perform the action. Element was not found

  2. XPATH=//div/div/div[3]/div/div/button//span[1]
    TimeoutException: Timeout occurred while trying to perform the action. Element was not found

3.XPATH=/html/body/div[1]/div[2]/div[5]/div/div/div[6]/div[3]/div[1]/div/div/div[3]/div/div/button/div/div/span[1]
TimeoutException: Timeout occurred while trying to perform the action. Element was not found

Thanks,
Sahani.

Try to use a different attribute to locate the element by.
Note that the timeout exception occurs most likely because bad locators.
If that still doesn’t work for you and you checked that your locators are valid,
Please contact us at our support chat.