I have a dialog box appearing on my page every time I open it. I want to close it so that I can proceed with my programming. The dialogue box is like this image
I trie
It seems you were pretty close. To close the dialog box appearing on your page you need to click on the element marked as X which is a tag. So to invoke
click()
on the desired element you need to wait for the desired element to be clickable as follows:
Code Block:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.landrover.co.uk");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.linkText("X"))).click();
System.out.println(driver.getTitle());
Console Output:
Starting ChromeDriver 2.40.565498 (ea082db3280dd6843ebfb08a625e3eb905c4f5ab) on port 15398
Only local connections are allowed.
Jun 18, 2018 2:52:08 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
Premium 4x4 Vehicles & Luxury SUVs - Land Rover UK
Browser Snapshot: