0

enter image description here

just as in the above image there is use of divs and every time the data (image) in that div changes. You are not even sure that how many divs will be therewith respect to row and columns. Kindly guide if any one has idea about it. Thanks.

  • 1
    What exactly do you want to check? The image? – beatngu13 Apr 26 at 17:43
  • No I just want to click on that image in the child div. Actually its and food item and after click on it, it will open a pop-up window. – Muhammad Atif Muneeb Alrai Apr 29 at 4:55
1

I am not sure I understand completly so here are two solutions:

If the image path does not change use css selector:

driver.findElement(By.cssSelector("div[background-image$='medium-chicken-fajita-recipe\");.jpg']"))

If the path does change and all you really need to do is select "some" product:

Query all divs that have a class 'card-item-img' and select any of them:

driver.findElements(By.className("card-item-img").get(1).click()

Personally if that is the case I would use a lamba:

driver.findElements(By.className("card-item-img")).stream().findFirst().orElseThrow(NotFoundException::new).click();
0

Here i can see that in your DOM that your image's path will unique, so if they will not change then you create the Xpath of that div using it's class and bakground-image.
and for further reference in making Xpath of background-image you can go through
HERE and HERE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.