我想在我的应用程序中自动化提交简历页面的代码。该页面包含一个要添加在资格详细信息中的部分,该部分进一步打开一个窗口以添加相同的内容。问题是打开的窗口有空白ID并且在其中自动执行相同的i get session expired消息,否则当我通过selenium ide或手动访问它时工作正常。附上代码以供参考。
我的代码如下: -
w.get("https://www.hrmantra.com/LetsLead/18_Recruitment/SubmittResume.aspx?cn=LetsLead");
String parentHandle = w.getWindowHandle();
w.findElement(By.xpath("//.//*[@id='lbAddQualification']")).click();
for (String winHandle: w.getWindowHandles()) {
w.switchTo().window(winHandle);
e = new Select(w.findElement(By.xpath("//.//*[@id='lstlist']")));
e.selectByVisibleText("A Level DOEACC");
w.findElement(By.xpath("//.//*[@id='Btnconadd']")).click();
w.findElement(By.id("BtnAdd")).click();
}
w.switchTo().window(parentHandle);
答案 0 :(得分:0)
切换后,您需要在循环外部使用正确的代码:
static WebDriver driver=null;
public static void main(String[] args) {
driver = new FirefoxDriver();
driver.get("https://www.hrmantra.com/LetsLead/18_Recruitment/SubmittResume.aspx?cn=LetsLead");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
String mainwindow=driver.getWindowHandle();
driver.findElement(By.xpath("//.//*[@id='lbAddQualification']")).click();
for(String winHandle :driver.getWindowHandles()){
driver.switchTo().window(winHandle);
}
// Here right your code which you want to perform on pop-up
driver.close();
// Back to main window
driver.switchTo().window(mainwindow);