Share
Go down
avatar
sanjeetravi
Regular Participant
Regular Participant
Posts : 27
Join date : 2012-07-10
Age : 27
Location : Delhi

click button of a pop up in webdriver

on Wed Jul 11, 2012 12:50 pm
HOW TO CLICK A OK BUTTON PRESENT IN A POPUP.
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

Re: click button of a pop up in webdriver

on Wed Jul 11, 2012 1:56 pm
//focus to the popup window using
driver.switchTo().window(windowname);

//click the button with any attribute
driver.findElement(By.xpath).click();
avatar
sanjeetravi
Regular Participant
Regular Participant
Posts : 27
Join date : 2012-07-10
Age : 27
Location : Delhi

Re: click button of a pop up in webdriver

on Mon Jul 16, 2012 11:54 am
But how will i found the name of the pop up window.??
popsha
Amateur
Amateur
Posts : 60
Join date : 2012-04-14

Re: click button of a pop up in webdriver

on Mon Jul 16, 2012 1:28 pm
avatar
sanjeetravi
Regular Participant
Regular Participant
Posts : 27
Join date : 2012-07-10
Age : 27
Location : Delhi

Re: click button of a pop up in webdriver

on Wed Jul 18, 2012 1:20 pm
Here is my code the id of my popup is "companySelectionPopup" by using the above commands its still shows the error that unable to find element with id j_idt76:j_idt82.

Somebody pls help its a big bottle neck for me as my project is full off popups
private WebDriver driver;
private String baseUrl;
String newSet;


@Before
public void setUp() throws Exception {
driver = new FirefoxDriver();
baseUrl = "http://192.168.0.101:7001/";
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}




@Test
public void Test7()throws Exception {
driver.get(baseUrl + "/SimonWeb/login.html");
driver.findElement(By.id("submit")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
newSet=driver.getWindowHandle();
driver.switchTo().window(newSet);
driver.findElement(By.id("j_idt76:j_idt82")).click();
}
@After
public void tearDown() throws Exception {
http://driver.quit();

}

}
naveenkhunteta
Posts : 2
Join date : 2012-07-18

Re: click button of a pop up in webdriver

on Wed Jul 18, 2012 6:19 pm
Hi Sanjit,

Is it a Java script pop-up or some window pop-up?
or its a kind of java script alert?

In webdriver, we have 3 different ways of handling these pop-ups and alerts.
try following code:

WebDriver driver=new FirefoxDriver();

Alert alert=driver.switchTo().alert(
); //Alert is an interface in Selenium and switchTo() and alert() are static methods of it.
alert.accept(); // it will click on OK button
alert.dismiss(); // it will click on Cancel button.
alert.getText(); // it will capture the text present on alert.
naveenkhunteta
Posts : 2
Join date : 2012-07-18

Re: click button of a pop up in webdriver

on Wed Jul 18, 2012 7:40 pm
And if its a pop up window try the following code----

//it will return all the FF windows Ids used by webdriver and capture these in a set collection.
set windowIds=driver.getWindowHandles();

Iterator itr=windowIds.iterator();
while (itr.hasNext()){
mainwindowID=itr.next(); // main window ID
popupwindowID=itr.next(); // pop-up window ID
}

driver.switchTo().window(popupwindowID);

//clicking on Ok button
driver.findElement(By.Xpath("---xpath of Ok button----")).Click

//Switch back to the main window pop-up
driver.switchTo().window(mainwindowID);
Sponsored content

Re: click button of a pop up in webdriver

Back to top
Permissions in this forum:
You cannot reply to topics in this forum