Home > front end >  element click intercepted in Selenium wedriver
element click intercepted in Selenium wedriver

Time:09-22

1trying to execute the below code

I was writing script where I used mouse hover code to click on join and then it would show membership screen with 3 different panels, I wrote code to click "join button" on free panel, but this isnt working as there is a window popup showing up and not letting the code run. please help

System.setProperty("webdriver.chrome.driver","C:\\Selenium\\Drivers\\chromedriver_win32\\chromedriver.exe");
        WebDriver driver= new ChromeDriver();
        driver.get("https://www.nvidia.com/en-us/geforce-now/");
        Thread.sleep(3500);
        Actions ac= new Actions(driver);
        ac.moveToElement(driver.findElement(By.linkText("Join Now"))).perform();
        driver.findElement(By.xpath("/html/body/div[1]/div/div[11]/section/div/div/div/div/div[1]/div/div/div/section/div/div[1]/a/div[2]/div[3]/div/div/button")).click();
        driver.close();

Getting the exception :

Exception in thread "main" org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element ... is not clickable at point (259, 649). Other element would receive the click: ...

CodePudding user response:

That is a push notification. You can disable that using ChromeOptions():

ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-notifications");
System.setProperty("webdriver.chrome.driver","C:\\Selenium\\Drivers\\chromedriver_win32\\chromedriver.exe");
WebDriver driver= new ChromeDriver(options);

If you decide to use WebDriverManager:

Add the following WebDriverManager dependency in your pom.xml (if you are using Maven project):

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency>
    <groupId>io.github.bonigarcia</groupId>
    <artifactId>webdrivermanager</artifactId>
    <version>5.3.0</version>
</dependency>

Otherwise download 'webdrivermanager-5.3.0.jar' file from the below path and add it to your project's build path:

https://repo1.maven.org/maven2/io/github/bonigarcia/webdrivermanager/5.3.0/webdrivermanager-5.3.0.jar

Then, use the below code:

import java.time.Duration;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeOptions;
import org.openqa.selenium.chrome.ChromeDriver;
import io.github.bonigarcia.wdm.WebDriverManager;

public class DisableNotifications {
    public static WebDriver driver;
    
    public static void main(String[] args) {
        WebDriverManager.chromedriver().setup();
        ChromeOptions options = new ChromeOptions();
        options.addArguments("--disable-notifications");
        driver = new ChromeDriver(options);
        driver.manage().window().maximize();
        driver.manage().timeouts().implicitlyWait(Duration.ofSeconds(10));
        driver.get("https://www.nvidia.com/en-us/geforce-now/");
    }
}

If you are working with any frameworks, modify this code according to that.

CodePudding user response:

You can use the JavascriptExecutor class to do this. Assuming that even if we don't close the window popup we are still able to proceed, this should solve your issue This method of clicking sends the click event directly to Element.

// Assume driver is a valid WebDriver instance that
// has been properly instantiated elsewhere.
WebElement element = driver.findElement(By.id("elementiD"));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
  • Related