-3

I'm trying to select the highlighted element below (which is a "window close" button):

enter image description here There is one other element with class='icon-Dismiss' on the page, but none with class='dialog-close'.

What I have tried so far:

driver.findElement(By.xpath("//*[@class='icon-Dismiss' and @class='dialog-close']"))
driver.findElement(By.className("dialog-close"))
driver.findElement(By.xpath("//*[@id='contentBox']"))

In all cases however, I receive the following error:

no such element: Unable to locate element

Does anyone have an idea on how I can select this element?

Guy
  • 46,488
  • 10
  • 44
  • 88
Vitesze
  • 13
  • 6
  • 1
    Please read why [a screenshot of code is a bad idea](https://meta.stackoverflow.com/questions/303812/discourage-screenshots-of-code-and-or-errors). Paste the code and properly format it instead. – JeffC Dec 11 '19 at 01:47

5 Answers5

1

You need to induce WebDriverWait for the desired elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("div.contentBox div.icon-Dismiss.dialog-close"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//div[@id='contentBox']//div[@class='icon-Dismiss dialog-close']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

Try using

driver.findElement(By.cssSelector(".icon-Dismiss.dialog-close"))

Also, make sure this element is not in an iFrame. If it is then you will need to switch to the iFrame first before you can find the element.

RKelley
  • 1,099
  • 8
  • 14
0

try this driver.switchTo().alert().dismiss(); if that dialog box is an alert.

Amruta
  • 1,128
  • 1
  • 9
  • 19
0

If you just want to locate then driver.findElement(By.cssSelector("div.icon-Dismiss.dialog-close"));

but if you want to just close the alert then alert().dismiss(); will be the best option.

0

If this is the window pop up try : driver.switchTo().alert().dismiss();

if this is application these locators should work

Note : make sure you are using waiting till popup appearing on page

Alok kumar
  • 11
  • 4