如何使用selenium webdriver在salesforce中的子窗口上使用sendkeys?

时间:2016-05-30 13:16:24

标签: selenium-webdriver salesforce

我想在这些screenshots 中显示的子窗口的搜索文本框上使用sendkeys

我能够在子窗口中找到URl和子窗口的标题名称,,只要我想要clicksendkeys,代码就会暂停之间的错误:org.openqa.selenium.NoSuchElementException: no such element

请建议如何解决上述问题。

1 个答案:

答案 0 :(得分:0)

希望没有框架,如果在新窗口中打开,请尝试以下内容:

Thread.sleep(2000);
// Store the current window handle
String winHandleBefore = driver.getWindowHandle();

// Perform the click operation that opens new window

// Switch to new window opened
for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);
}

// Perform the actions on new window
driver.findElement(By.xpath("ur xpath of that search box")).click();
driver.findElement(By.xpath("ur xpath of that search box")).clear();
driver.findElement(By.xpath("ur xpath of that search box")).sendKeys("ur text");


// Close the new window, if that window no more required
driver.close();

// Switch back to original browser (first window)
driver.switchTo().window(winHandleBefore);