EVEN MORE NEW INFORMATOIN: I'm now officialy confused as to why this test is slow. I've eliminated the need for javascript as descripbed below and I've added reporting to determine where things are being delayed. these are the lines that start with "logger". I've added the timestamps behind these lines so you can see where the delay is. This is the section of code where it looks like it messes up/takes pretty long (10min every time):
wait.until(ExpectedConditions.elementToBeClickable(By.id("ID")));
logger.log(LogStatus.INFO, "Waituntill is done and element is clickable"); /** logged as successfull at 17:45:51 */
driver.findElement(By.xpath("//div[@class='CLASS']")).click();
logger.log(LogStatus.INFO, "menu visible"); /** logged as successfull at 17:45:52 */
driver.findElement(By.xpath("//*[@class='CLASS' and text()='TEXT']")).click();
logger.log(LogStatus.INFO, "menu item is available and clickable."); /** logged as successfull at 17:55:47 */
Strange thing is that if you follow the process of the test the final step (click) shows right away as this opens a new window. This is not 10 minutes later. It seems as after this step a 10 delay is built in. But there is no such thing in my code. The code above is followed by:
Set <String> handles =driver.getWindowHandles();
Iterator<String> it = handles.iterator();
//iterate through your windows
while (it.hasNext()){
String parent = it.next();
String newwin = it.next();
driver.switchTo().window(newwin);
driver.switchTo().defaultContent();
logger.log(LogStatus.INFO, "timestamp1 defaultcontent"); /** logged as successfull at 17:55:47 */
WebElement frame=driver.findElement(By.xpath("/html/body/iframe"));
logger.log(LogStatus.INFO, "timestamp2 find xpath for iframe"); /** logged as successfull at 17:55:47 */
driver.switchTo().frame(frame);
logger.log(LogStatus.INFO, "timestamp3 switch to iframe"); /** logged as successfull at 17:55:47 */
assertEquals("PageTitle", driver.getTitle());
logger.log(LogStatus.INFO, "timestamp4 confirm switch to iframe succesfull"); /** logged as successfull at 17:55:47 */
NEW INFORMATION: I've studied my code and it looks like I'm not correct on where the delay occurs. it now looks like it occurs where I change the style of an element so that it shows and another element becomes clickable. I am now using the following code to change the style but this may be the problem. Is there an easier or better way to change the style of an element?
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.xpath("//div[@class='button_ribbon_dropdownsection']"));
js.executeScript("arguments[0].setAttribute('style', 'left: 1520px; top: 40px; display: block;')",element);
ORIGINAL POST: I have a testcase where I click on a link that opens a pop-up. In this pop-up is an iFrame that contains fields I want to assert and fill. However, running this case takes about 10 minutes and I don't know why. Here is my code:
//this is the link I click that opens the new window
driver.findElement(By.xpath("//*[@class='value' and text()='text']")).click();
//I have inserted this section to switch to the correct window (the popup). If I don't inlcude this the focus remains on the window where I clicked the link that opens the pop-up.
Set <String> handles =driver.getWindowHandles();
Iterator<String> it = handles.iterator();
//iterate through your windows
while (it.hasNext()){
String parent = it.next();
String newwin = it.next();
driver.switchTo().window(newwin);
//this is where I switch to the iFrame in the new window in order to reach the desired elements
WebElement testframe=driver.findElement(By.xpath("/html/body/iframe"));
driver.switchTo().frame(testframe); /** this section may take up to 10-15 minutes */
assertEquals("pagetitle here", driver.getTitle());
assertEquals("value", driver.findElement(By.id("id")).getText());
driver.findElement(By.id("id")).clear();
driver.findElement(By.id("id")).sendKeys("number");
This code does run so there is no fault in the code (that I can find) but it just takes VERY long and I can't figure out why.
I know going to the iFrame via an Xpath is not the best method but it is a commercial product and there is no id or name for the iframe so I can't navigate to it that way.
I'm using Eclipse with Selenium webdriver and Java.