Handling PopUs in Selenium - java

How to remove an alert that is not having any ok/Cancel button .It just have a link to which i will be redirected to and small cross button at top right of it.
example : An activity is pending with me . Every time i login to website it shows me an alert to complete the Activity . It is not having Ok or Cancel button.
driver.switchTo().alert().dismiss(); is not working . Any suggestion ??
Given is the Alert Pic

Try locating "X" in upper left corner with
driver.findElement(By....)).click();
maybe it should dismiss notification.

Related

Using 'Alert' Interface in Selenium Java for alert conformation not working as expected

I used below selenium codes to click "OK" alert box, But It is not identifying, I dont knw wht's the reason, Can anyone help to solve this Issue ?
Element image:
Code trials:
Alert click_on_update_button_Htwelveyes = driver.switchTo().alert();
click_on_update_button_Htwelveyes.accept();
}
Console Output:
org.openqa.selenium.NoAlertPresentException: no such alert
(Session info: chrome=103.0.5060.134)
Alert
An alert box is used if the user wants to make sure information comes through to the user. The user will have to click on OK to agree or Cancel to deny the information.
This usecase
The following element doesn't seems to be an alert but a Modal Dialog Box :
In such cases you need to locate the element with the Modal Dialog Box to locate the element with text as Yes or No and invoke click() on the respective element of youe choice.

Unable to click on 'OK' button in the web alert

Am trying to click on 'OK' button in the attached popup using selenium webdriver alert interface.
When I inspected the 'OK button using accessibility inspector, it has shown the below properties.
target.processes()["Google Chrome"].frontWindow().images()["Chrome critical alert"].click()
target.processes()["Google Chrome"].frontWindow().buttons()["OK"].click()
So, I have tried webdriver alert to click on 'OK', but it didnt work.
Alert alert = driver.switchTo().alert();
alert.accept();
Have spent enough time on this but couldnt find a solution.Appreciate any help here !
That doesn't look like a browser "alert" box to me, so the Alert method won't find it. It also doesn't look like a "popup" (a separate desktop window) in the usual sense. I'm guessing from your description that it's a conventional HTML element on the page. Therefore, you need to find the OK button by usual Selenium element-finding techniques and then click() on the element.

Selenium Java Chrome send enter key while the elements on the page are disabled

I need to close a dialog box that pops up after I had selected 'Save' by clicking 'Ok', however none of the elements on the page as well as dialog box can be inspected by right clicking after the pop-up (tried F12 doesn't help).
Alternatively, to close the dialog box enter key could be given, however I'm unable to send the enter key as listed below.
Actions action = new Actions(driver); //attempt 1
action.sendKeys(Keys.RETURN);
action.sendKeys(Keys.RETURN).perform(); //attempt 2
Both actions does not close the dialog box. I had performed the driver switch as well. In addition to the dialog box pop-up there's also an outlook email pop-up could this create an issue in identifying the alert pop-up? Kindly advise on how enter key could be passed to close the dialog box.
Found the issue, it was due to Thread.sleep(3000) that I had used after the click, guess this caused it to miss the alert from being recognized. I might be worng as well. Thanks for all your help!
As none of the elements can be inspected by right clicking after the pop-up which indicates its an Alert which is Javascript generated and you can use the following line of code :
Alert myAlert = new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
myAlert.accept();
Update A
As per the comment update :
Observation : In addition to the alert msg there's also outlook mail also pops up
Conclusion : If outlook mail pops up possibly it's not an Alert as suspected. You should be able to track the element within the HTML DOM.
Update B
As per the comment update :
Observation : there are 2 thing happens when i click on 'Save': [1]: Outlook email pop-up [2]: Alert notification on the saved page stating the records are being updated
Conclusion : Sounds like two window_handles opening up, treat them as window_handles.
Solution 1 : Try switching to the pop up and handle it.
new WebDriverWait(driver, 15).until(ExpectedConditions.alertIsPresent());
driver.switchTo().alert().accept();
Solution 2 : If you want to go with Keyboard keys.
Actions action = new Actions(driver);
new WebDriverWait(driver, 15).until(ExpectedConditions.alertIsPresent());
action.sendKeys(Keys.RETURN).perform();
In both cases, use 'wait' until you get an alert.
First, check the dialog box that pops up after you click 'Ok' is JavaScript Alert or anything else?
If the dialog is JavaScript Alert then try below code.
new WebDriverWait(driver, 10).until(ExpectedConditions.alertIsPresent());
Alert alert = driver.switchTo().alert();
alert.accept();

Click() is not performing on Fb message(left panel) and Home button

I tried different xpath (relative and absolute) and perform .click() on them in Facebook message (left panel) and Home button on upper nav bar but the element is highlighted (like when you hover the mouse pointer on it) but not clicking on them.
My code snippet is like this:
d.findElement(By.xpath("//div[#class='_59g8']/div[#class='clearfix']/div[1]/ul[1]/li[2]")).click();
Thread.sleep(1000L);
d.findElement(By.xpath("//div[#id='pinnedNav']/ul[1]/li[2]")).click();
After login fb page. You can try with the below lines of code, it will perform click action on Home and Message Button.
d.findElement(By.linkText("Home")).click();
Thread.sleep(1000);
d.findElement(By.partialLinkText("Messages")).click();

clicking "next page button", the page shows next page but the source codes of the page remains the same

I use selenium driver(chrome) to visit a commercial search engine. The problem is that when I click the "next page" button manually, it turns out the next page items,i.e. more search results show up. Surprisingly, when I check the source by right clicking the mouse "view page source" on the "next page", the source codes are the same as the former page! That is to say, something hides the page source of the current(next page) page! When I right click the "save as" to save all information on my local disk, source page of the "next page" does show up! Why is that?
More worse, I use chromedriver to find the button "NextItem" and click it, but there is an "not clickable" error like this:
unknown error: Element is not clickable at point (452, 202). Other element would receive the click: ...
The part of my codes:
List<WebElement> nextItems = chrome.findElementsByClassName("nextItem");
nextItems.get(0).click();
String sourePage=chrome.getPageSource();
THEN CRASH....
Why I can manually click the button but it cannot be clicked by the chromedriver?
Need help!
When executing tests using ChromeDriver, the "Element not clickable" error does happen if ChromeDriver attempts to "click" the element at an (x, y) location that is not actually clickable. A workaround for this in C# is located at comment 27: https://code.google.com/p/selenium/issues/detail?id=2766

Categories

Resources