I am writing selenium web driver automation test cases. sometimes i see this weird behavior in selenium. I run my tests(TESTNG) and it run successfully and i again run the same code nothing happens.
Again the same problem came to me with the following code
I am just writing one method here
@BeforeTest
public void method(){
driver.get("http://site.staging.snapdeal.com:7003/product/intex-aqua-n2-white/737345766");
driver.manage().window().maximize();
window = driver.getWindowHandle();
driver.switchTo().frame("loginIframe");
driver.findElement(By.id("close-pop")).click();
driver.switchTo().window(window);
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("BuyButton-2")));
productName=driver.findElement(By.xpath(".//div[@class='productTitle']//h1")).getText();
System.out.println("Product Name : "+productName);
driver.findElement(By.id("BuyButton-2")).click();
wait.until(ExpectedConditions.presenceOfElementLocated(By.className("cart-scroll")));
System.out.println("button clicked");
}
once this code will run fine and just on another run my program gets lost in some other world neither does it throws any exception nor times out.. just the browser comes to an idle state after the 4th last line driver.findElement(By.id("BuyButton-2")).click();
this button gets clicked the required action (opening of cart) occurs and then the browser is still. i do not see the "button clicked" output on my console
I do have the driver.quit(); call in my @Aftertest method.
but neither the driver quits nor does it throws any exception and nothing on the console either.
is something wrong with my code?