I have an alert with a OK button that I need to click, but nothing I've tried seems to work on it. My code can identify the alert, but as soon as I try to perform an action it, it seems to interact with the screen behind the alert.
It's a native iOS app that I'm working with. I've tried the following options:
1. driver.switchTo().alert().accept();
2. driver.switchTo().alert().dismiss;
3. driver.switchTo().alert();
driver.findelement(By.id("OK")).click();
4. TouchAction touchAction = new TouchAction(driver).tap(xCoordinates, yCoordinates);
touchAction.perform();
Does anyone know of another way to click on this alert?
Add a capability capabilities.setCapability("autoGrantPermissions", true); in appium your capabilities list! It will allow to accept or OK automatically. My same issue was resolved!
Seems to me a synchronizing issue and a simple solution would be to induce WebDriverWait with ExpectedConditions as alertIsPresent() as follows :
Accept Alert :
new WebDriverWait(driver, 20).until(ExpectedConditions.alertIsPresent()).accept();
Dismiss Alert :
new WebDriverWait(driver, 20).until(ExpectedConditions.alertIsPresent()).dismiss();
Update
As an alternative, you can try the following code block :
//import
import org.openqa.selenium.Alert;
//code block
WebDriverWait wait = new WebDriverWait(driver, 5);
wait.until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();
Related
We are working on IE Automation using Selenium Web driver in C#.Net.
We are getting an exception in handling model popup window. We supposed to do below the action.
When we click on Link button it will open a popup window then we need switch to popup window selecting check box options and click on Submit button.
When clicking on Link button we are able to open the popup window. But here we are facing an issue like the child popup window is not loading with data and getting HTTP 500 Internal server Error.
I don't understand sometimes it was working properly with the same code but not all the times I am getting above issue when I am trying to perform above actions on child window.
is this any IE settings issue or my code issue even i ignored protected mode settings in IE settings.
I am trying with below code :
js.ExecuteScript("arguments[0].click();", driver.FindElement(By.XPath("//*[#id='ByNewNotes']")));
(or)
string jsWindowString = "NewWindow('pop_Type.jsp?Type=External&IuserId=NUVJK50'," + sessionId + ",'400','500');return false";
((IJavaScriptExecutor)driver).ExecuteScript(jsWindowString);
Could you please help on this issue.
Thanks in Advance.
Instead of using ExpectedConditions.ElementExists use ExpectedConditions.elementToBeClickable or presenceOfElementLocated
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(""//*[#id='ByNewNotes']")));
element.click();
Either Try to use FluentWait. Create a by function of your element which you want to wait and pass it in below method
WebElement waitsss(WebDriver driver, By elementIdentifier){
Wait<WebDriver> wait =
new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS) .pollingEvery(1, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
return wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver) {
return driver.findElement(elementIdentifier);
}});
}
Hope it will help you :)
Have you tried
Thread.Sleep(2000);
We had the same issues and solved it with this simple way.
After clicking save button a pop will open and i write a code below to do accept but its not working.
`driver.findElement(By.id("save")).click();
Alert succ=driver.switchTo().alert();
System.out.println(succ.getText());
Thread.sleep(2000);
succ.accept();`
Need Help please.
The behavior of selenium varies according to browser, In some case the actions done in Firefox browser like form filling actions or clicking the button is faster then Chrome browser so your script well executed in chrome but throw error in Firefox so you need to add some pause to make them perform well.
So in your case after clicking the save button selenium executing the command too fast so skip to switch on alert and accept so add some wait using Thread.sleep(); to make pause
driver.findElement(By.id("save")).click();
Thread.sleep(2000);
Alert succ=driver.switchTo().alert();
System.out.println(succ.getText());
Thread.sleep(2000);
succ.accept();
Note : It is not recommended to use Thread.sleep(); instead use implicit or explicitwait conditions
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.alertIsPresent());
Try this:
driver.findElement(By.id("save")).click();
try {
Thread.sleep(3000);
} catch (InterruptedException e) {
e.printStackTrace();
}
System.out.println(driver.switchTo().alert().getText());
driver.switchTo().alert().accept();
Does anyone know how to click log out button? I tried using driver.findElement(By.linkText("Log out"));
But it returned an error saying element is not found. Is it because the list is dynamically generated?
You should try using WebDriverWait to wait until elementToBeClickable it works for me as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement accountSettings = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Account Settings")));
accountSettings.click() //this will click on setting link to open menu
WebElement logOut = wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Log Out")));
logOut.click() // this will click on logout link
Hope it helps...:)
I assume, after click on arrow button, Log Out button appers in ur code. So to click on that log Out button, use the below portion as cssSelector:
a[data-gt*='menu_logout']>span>span._54nh
driver.findElement(By.cssSelector("a[data-gt*='menu_logout']>span>span._54nh"));
I am not sure whether selenium web driver can handle JavaScript alert/pop-up window.
I have a scenario like
Enter URL
Alert/Pop-up window will be displayed .User need to enter User name and Password and Click "OK" on window
You can handle it by many ways
WebDriverWait wait = new WebDriverWait(driver, 20);
Alert alert = wait.until(ExpectedConditions.alertIsPresent());
alert.authenticateUsing(new UserAndPassword(**username**, **password**));
OR
driver.get("http://UserName:Password#Example.com");
Hope it will help you :)
After posting information in my webapp, I get this warning dialog box
"Although this page is encrypted, the information you have entered is to be sent over an unencrypted connection and could easily be read by a third party.
Are you sure you want to continue?
<button> Continue <button> Cancel
How do I select "Continue" using selenium. Already tried for Conformation and alert, not working.
If its a windows dialog box use the following code
Alert alert = driver.switchTo().alert();
alert.accept();
Hope this helps you
Is it a window?? In that case try following:
String winHandle = driver.getWindowHandle(); //Get current window handle.
for(String windowsHandle : driver.getWindowHandles()) {
driver.switchTo().window(windowsHandle); //Iterate to the new window handle.
}
/*
Do any action on window or just close it.
*/
driver.close();
driver.switchTo().window(winHandle); //Switch to original window.
See if it helps you.
You can try keyboard actions instead:
import org.openqa.selenium.Keys;
import org.openqa.selenium.interactions.Actions;
private void handleWindow(boolean continue)
{
Actions actions = new Actions(driver);
if (continue)
actions.sendKeys(Keys.RETURN).build().perform();
else
actions.sendKeys(Keys.TAB).sendKeys(Keys.RETURN).build().perform();
}