問題描述
我的問題是硒給出了異常可見的元素.我不明白這一點(diǎn),因為當(dāng)我在我的機(jī)器上進(jìn)行構(gòu)建時!(測試建立在竹子上).
My problem is that selenium give the exception so visible elements. I don't understand this because when I put to build in my machine works! ( The tests build at bamboo).
這是一個例外:
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with Command duration or timeout: 30.06 seconds Build info: version: '2.44.0', revision: '76d78cf323ce037c5f92db6c1bba601c2ac43ad8', time: '2014-10-23 13:11:40' System info: host: 'N/A', ip: 'N/A', os.name: 'Linux', os.arch: 'amd64', os.version: '3.2.0-52-virtual', java.version: '1.7.0_72' Session ID: 1757208d-d49e-4792-b053-e55e7300c233 Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{platform=LINUX, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, nativeEvents=false, webStorageEnabled=true, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=34.0}]
org.openqa.selenium.ElementNotVisibleException: Element is not currently visible and so may not be interacted with
Command duration or timeout: 30.06 seconds
代碼:
String name;
String key;
@Before
public void setUp() throws InterruptedException {
driver.findElement(By.id("menu_topMenu.maintenance")).click();
Thread.sleep(1000);
driver.findElement(By.id("menu_topMenu.route")).click();
}
@Test
public void test() throws InterruptedException {
AddRoute addRoute = new AddRoute(driver);
addRoute.add();
name = addRoute.getName();
key = addRoute.getKey();
Thread.sleep(3000);
driver.findElement(By.cssSelector
("#Route_btn_novo")).click();
driver.findElement(By.cssSelector
("#Route_key > input[type="text"]")).sendKeys(key);
driver.findElement(By.cssSelector
("#Route_description > input[type="text"]")).clear();
driver.findElement(By.cssSelector
("#Route_description > input[type="text"]")).sendKeys(name);
driver.findElement(By.cssSelector
("#Route_organization > div.lookUpHitArea")).click();
driver.findElement(By.cssSelector
("#MonetUIFieldsLookupGridContainer_organization > div.slick-pane.slick-pane-top.slick-pane-left > div.slick-viewport.slick-viewport-top.slick-viewport-left > div > div:nth-child(2) > div.slick-cell.l0.r0.cell-row")).click();
driver.findElement(By.cssSelector
("#Route_plannedCost > input")).sendKeys("10000");
driver.findElement(By.cssSelector
("#Route_origin > div.lookUpHitArea")).click();
driver.findElement(By.cssSelector
("#MonetUIFieldsLookupGridContainer_location > div.slick-pane.slick-pane-top.slick-pane-left > div.slick-viewport.slick-viewport-top.slick-viewport-left > div > div:nth-child(1) > div.slick-cell.l1.r1.cell-row.selected")).click();
driver.findElement(By.cssSelector
("#Route_lastStopIsDestination > input")).click();
Thread.sleep(1000);
driver.findElement(By.cssSelector
("#Route_btn_save_and_close")).click();
Thread.sleep(3000);
assertTrue("Rota existente nao validada corretamente",
isDisplayedByCssSelector(driver, "#form_and_grid > div > div.monetInlineAlerContainer > div"));
}
}
我不知道該怎么辦了!
推薦答案
我不確定你的整個設(shè)置是什么樣子的.但是,一種常見的做法是在這種情況下使用 Selenium Grid.這個想法是擁有一個 selenium 集線器和多個從屬設(shè)備(根據(jù)您的需要,可能是虛擬機(jī)),并讓 CI 服務(wù)器控制從屬設(shè)備來執(zhí)行測試.您遇到的問題是因為 CI 服務(wù)器的行為不像您的本地機(jī)器那樣.該元素不可見意味著 selenium 無法與瀏覽器進(jìn)行交互,它不應(yīng)該在 CI 上進(jìn)行交互.請參閱 this 了解有關(guān)網(wǎng)格.這應(yīng)該可以幫助您入門.
I am not sure how your entire set up looks like. But, a common practice is to use Selenium Grid in such case. The idea is to have a selenium hub and multiple slaves(as many as you need and may be virtual machines) and have the CI server controlling the slaves to execute the tests. The issue you are having is because of CI server is not acting like your local machine is doing. The element is not visible means selenium is not able to interact with the browser which it should not on CI. See this to explore more about the grid. This should help you to get started.
注意:這是從 CI 執(zhí)行 selenium 測試的眾多方法之一
這篇關(guān)于org.openqa.selenium.ElementNotVisibleException:元素當(dāng)前不可見,因此可能無法與命令持續(xù)時間或超時交互:的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!