2013-02-01 98 views
0

我在Java中使用Internet Explorer和Selenium Webdriver。在Selenium Webdriver彈出窗口中找不到元素

我加載一個URL,同時打開另一個窗口,其中有登錄框。 使用提到的方法here

我可以選擇所需的窗口和send keys到焦點框中。

popup.getKeyboard().sendKeys("yeuiryuiryweuiryeuiyterui"); 

但是,下面的:

popup.findElement(By.id("userName")).sendKeys("user") 

是無法找到的元素,並拋出一個異常Element-not-found(與此類似)。

我在哪裏弄錯了?

+0

什麼是getKeyboard()方法? – Manigandan

+0

它用於將鍵發送給聚焦的元素。 – sbose

回答

0

我會建議你使用XPath

String locator = "//*[@class='Class name of user name text box'and text()='if any']" 

嘗試,你可以通過螢火蟲

List<WebElement> element = Driver.driver.findElements(By.xpath(locator)); 

THN網頁元素上使用點擊功能查找用戶名,做同樣的密碼,然後單擊在登錄時直接使用Driver.selenium.click(xpath);並提供登錄按鈕的xpath,以防事件ID不存在。

相關問題