So I started a new Project with Selenium in Android Studio with Java and it seems like that I have run into a problem. What I am trying to do is to open instagram then to click on the only essential cookies , to fill out the name and password until then it works perfectly but after that it won't press the login button no matter what I try it will just stop So this is my code (I changed my Username and Password of course):
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public static void main(String[] args) {
System.setProperty("webdriver.safari.driver","/usr/bin/safaridriver");
SafariDriver driver = new SafariDriver();
driver.get("https://www.instagram.com/accounts/login/?hl=en&source=auth_switcher");
new WebDriverWait(driver, Duration.ofSeconds(10));
driver.findElement(By.className("HoLwm")).click();
driver.findElement(By.name("username")).sendKeys("xyzzy");
driver.findElement(By.name("password")).sendKeys("xyzzy");
new WebDriverWait(driver, Duration.ofSeconds(10));
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(20));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("\"//button[@type='submit']\"")));
driver.findElement(By.xpath("\"//button[@type='submit']\"")).click();
new WebDriverWait(driver, Duration.ofSeconds(10));
}
and somehow I get an error :
Exception in thread "main" org.openqa.selenium.TimeoutException: Expected condition failed: waiting for element to be clickable: By.xpath: "//button[@type='submit']" (tried for 20 second(s) with 500 milliseconds interval)
Build info: version: '4.1.3', revision: '7b1ebf28ef'
Driver info: org.openqa.selenium.safari.SafariDriver
Capabilities {acceptInsecureCerts: false, browserName: Safari, browserVersion: 15.4, javascriptEnabled: true, platform: MAC, platformName: MAC, safari:automaticInspection: false, safari:automaticProfiling: false, safari:diagnose: false, safari:platformBuildVersion: 20G527, safari:platformVersion: 11.6.5, safari:useSimulator: false, setWindowRect: true, strictFileInteractability: false, webkit:WebRTC: {DisableICECandidateFiltering: false, DisableInsecureMediaCapture: false}}
Session ID: D249B2A9-5C9F-4000-A778-8D9B4D81A240
at org.openqa.selenium.support.ui.WebDriverWait.timeoutException(WebDriverWait.java:87)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:231)
at com.example.instagramrepost.MainActivity.main(MainActivity.java:39)
can someone pls help me thank you
I have found the answer:
WebElement element = driver.findElement(By.cssSelector("button[type='submit']"));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
This code works 100% of the time But still thanks to those who tried to help me with the issue