我正在写一个TestNg
脚本,我要关闭模式框并在浏览器上执行操作。我能够关闭模态
但无法在浏览器上执行任何操作。
driver.findElement(By.id("username")).clear();
driver.findElement(By.id("username")).sendKeys(userName1);
driver.findElement(By.id("password")).clear();
driver.findElement(By.id("password")).sendKeys(password1);
driver.findElement(By.id("Login")).click();
Thread.sleep(5000);
switchtoLightining();
driver.findElement(By.linkText("App Launcher")).click();
driver.findElement(By.linkText("ICIX")).click();
driver.findElement(By.linkText("Document Library")).click();
driver.switchTo().frame(driver.findElement(By.id("vfFrameId")));
driver.findElement(By.id("btn_AddDocument")).click();
new Select(driver.findElement(By.id("ddTemplate")))
.selectByVisibleText("GFSI Certification");
driver.findElement(By.id("createButton")).click();
// Get the current window handle
String winHandleBefore = driver.getWindowHandle();
Thread.sleep(5000);
// Get the list of window handles
ArrayList<String> tabs2 = new ArrayList<String>(
driver.getWindowHandles());
System.out.println("size is:" + tabs2.size());
driver.switchTo().window(tabs2.get(0));
Robot rb = new Robot();
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_TAB);
Thread.sleep(2000);
rb.keyPress(KeyEvent.VK_ENTER);
Thread.sleep(2000);
// Click on the upload button
// Switch to the parent old window
driver.switchTo().window(winHandleBefore);
Thread.sleep(2000);
driver.findElement(By.xpath("//button[@class='slds-button slds-button--brand slds-m-horizontal--small']")).click();*/
driver.findElement(By.xpath(".//[@id='uploadButton']")).click();
答案 0 :(得分:0)
根据切换到该模型窗口之前提供的代码,您位于框架内。所以我希望你可能需要在
之后切换到相框 driver.switchTo().window(winHandleBefore);
点击上传按钮。
如果上传按钮不在框架中,只需看到gettitle或getcurrenturl会让你的父或winHandleBefore将交叉驱动程序切换到窗口。如果驱动程序正确切换到winHandleBefore,则发出上传元素定位器。请检查一次。
谢谢你, 穆拉利