Hello guys , im new to appium , i have installed all the prerequisite to began this , but i have a problem in my code , i want just to open google driver , but the cookies are blocking me so i decided to inspect the element and accept the button when the pop up appear ( i also tried to disable the cookies but not working ) , but when i run my application its open google scroll down to my pop up but dont click on it … , will let you with my code and the error :
import io.appium.java_client.AppiumDriver;
import io.appium.java_client.android.AndroidDriver;
import io.appium.java_client.remote.MobileCapabilityType;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeOptions;
import java.net.URL;
public class LaunchChrome {
public static void main(String[] args) {
try {
openChrome();
} catch (Exception exp) {
System.out.println(exp.getCause());
System.out.println(exp.getMessage());
exp.printStackTrace();
}
}
public static void openChrome() throws Exception {
ChromeOptions options = new ChromeOptions();
options.addArguments("--disable-cookies");
options.addArguments("--disable-popup-blocking");
options.addArguments("--disable-notifications");
DesiredCapabilities cap = new DesiredCapabilities();
cap.setCapability(MobileCapabilityType.DEVICE_NAME, "emulator-5554");
cap.setCapability(MobileCapabilityType.BROWSER_NAME, "Chrome");
cap.setCapability(MobileCapabilityType.AUTOMATION_NAME, "UiAutomator2");
cap.setCapability(ChromeOptions.CAPABILITY, options);
URL url = new URL("http://127.0.0.1:4723/wd/hub");
AppiumDriver driver = new AndroidDriver(url, cap);
driver.get("https://www.google.com");
// Find the accept cookies button by its CSS selector
WebElement acceptButton = driver.findElement(By.cssSelector("#L2AGLb"));
// If the accept button is displayed, click it
if (acceptButton.isDisplayed()) {
acceptButton.click();
}
// Find the refuse cookies button by its ID
//driver.quit();
}
}
the eroor :
null
element click intercepted: Element is not clickable at point (196, 1245)
(Session info: chrome=110.0.5481.65)
Build info: version: ‘4.8.0’, revision: ‘267030adea’
System info: os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘17.0.6’
Driver info: io.appium.java_client.android.AndroidDriver
Command: [195f17e9-0c40-4241-9f66-97ece9c1a387, clickElement {id=4b600d6f-70dd-4ace-a428-b62311c13c43}]
Capabilities {appium:appActivity: com.google.android.apps.chr…, appium:appPackage: com.android.chrome, appium:automationName: UiAutomator2, appium:databaseEnabled: false, appium:desired: {automationName: UiAutomator2, browserName: chrome, deviceName: emulator-5554, goog:chromeOptions: {args: [–disable-cookies, --disable-popup-blocking, --disable-notifications], extensions: []}, platformName: android}, appium:deviceApiLevel: 30, appium:deviceManufacturer: Google, appium:deviceModel: sdk_gphone_x86, appium:deviceName: emulator-5554, appium:deviceScreenDensity: 440, appium:deviceScreenSize: 1080x2280, appium:deviceUDID: emulator-5554, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:pixelRatio: 2.75, appium:platformVersion: 11, appium:statBarHeight: 135, appium:takesScreenshot: true, appium:viewportRect: {height: 1842, left: 0, top: 135, width: 1080}, appium:warnings: {}, appium:webStorageEnabled: false, browserName: chrome, goog:chromeOptions: {args: [–disable-cookies, --disable-popup-blocking, --disable-notifications], extensions: []}, platformName: ANDROID}
Element: [[AndroidDriver: chrome on ANDROID (195f17e9-0c40-4241-9f66-97ece9c1a387)] -> css selector: #L2AGLb]
Session ID: 195f17e9-0c40-4241-9f66-97ece9c1a387
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element is not clickable at point (196, 1245)
(Session info: chrome=110.0.5481.65)
Build info: version: ‘4.8.0’, revision: ‘267030adea’
System info: os.name: ‘Windows 10’, os.arch: ‘amd64’, os.version: ‘10.0’, java.version: ‘17.0.6’
Driver info: io.appium.java_client.android.AndroidDriver
Command: [195f17e9-0c40-4241-9f66-97ece9c1a387, clickElement {id=4b600d6f-70dd-4ace-a428-b62311c13c43}]
Capabilities {appium:appActivity: com.google.android.apps.chr…, appium:appPackage: com.android.chrome, appium:automationName: UiAutomator2, appium:databaseEnabled: false, appium:desired: {automationName: UiAutomator2, browserName: chrome, deviceName: emulator-5554, goog:chromeOptions: {args: [–disable-cookies, --disable-popup-blocking, --disable-notifications], extensions: []}, platformName: android}, appium:deviceApiLevel: 30, appium:deviceManufacturer: Google, appium:deviceModel: sdk_gphone_x86, appium:deviceName: emulator-5554, appium:deviceScreenDensity: 440, appium:deviceScreenSize: 1080x2280, appium:deviceUDID: emulator-5554, appium:javascriptEnabled: true, appium:locationContextEnabled: false, appium:networkConnectionEnabled: true, appium:pixelRatio: 2.75, appium:platformVersion: 11, appium:statBarHeight: 135, appium:takesScreenshot: true, appium:viewportRect: {height: 1842, left: 0, top: 135, width: 1080}, appium:warnings: {}, appium:webStorageEnabled: false, browserName: chrome, goog:chromeOptions: {args: [–disable-cookies, --disable-popup-blocking, --disable-notifications], extensions: []}, platformName: ANDROID}
Element: [[AndroidDriver: chrome on ANDROID (195f17e9-0c40-4241-9f66-97ece9c1a387)] -> css selector: #L2AGLb]
Session ID: 195f17e9-0c40-4241-9f66-97ece9c1a387
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at java.base/jdk.internal.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:77)
at java.base/jdk.internal.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:499)
at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:480)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:200)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:133)
at org.openqa.selenium.remote.codec.w3c.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:53)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:184)
at io.appium.java_client.remote.AppiumCommandExecutor.execute(AppiumCommandExecutor.java:262)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:543)
at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:257)
at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:78)
at LaunchChrome.openChrome(LaunchChrome.java:45)
at LaunchChrome.main(LaunchChrome.java:14)
Process finished with exit code 0