I switch from window A to window B.When i try to perform an action on window B,it throws No such element exception.I am new to selenium webdriver.Please help me out.
我的要求: 1)转到http://www.kotak.com/bank/personal-banking/convenience-banking/net-banking.html 2)点击安全登录 3)切换到新打开的窗口并填写用户名和密码在里面。在这个窗口中定位用户名和密码会抛出错误。
My code :
import java.util.Iterator;
import java.util.Set;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class WindowHandler1 {
public static void main(String args[]) throws InterruptedException
{
WebDriver driver = new FirefoxDriver();
driver.get("http://www.kotak.com/bank/personal-banking/convenience- banking/net-banking.html");
Thread.sleep(5000);
driver.findElement(By.xpath(".//*[@id='label-01']/a[1]")).click();
Set<String> windowids = driver.getWindowHandles();
Iterator<String> iter = windowids.iterator();
System.out.println(windowids);
String mainWindowId = iter.next();
String tabedWindowId = iter.next();
Thread.sleep(2000L);
// switching to the new pop up window
driver.switchTo().window(tabedWindowId);
Thread.sleep(20000);
//getting no such element exception upon executing line below
driver.findElement(By.xpath(".//*[@id='Username']")).sendKeys("username");
driver.findElement(By.id("Username")).sendKeys("abc");
} }