我在Selenium 2 Web驱动程序测试中有以下代码,它在我调试时有效,但是当我在构建中运行它时大部分时间都失败了.我知道它必须与页面没有刷新的方式有关,但不知道如何解决它所以任何关于我做错了什么的指针都很感激.我使用JSF primefaces作为我的Web应用程序框架.当我点击添加新链接时,会出现一个弹出对话框,其中包含一个我可以输入日期的输入框,然后单击保存.它是在输入元素输入文本,我得到一个陈旧的元素引用异常.
提前致谢
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.StaleElementReferenceException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;
public class EnterActiveSubmissionIntegrationTest {
Map<String, Map<String, String>> tableData = new HashMap<String, Map<String, String>>();
@Test
public void testEnterActiveSubmission() throws Exception {
// Create a new instance of the Firefox driver
// Notice that the remainder of the code relies on the interface,
// not the implementation.
System.setProperty("webdriver.chrome.driver", "C:/apps/chromedriver.exe");
WebDriver driver = …
Run Code Online (Sandbox Code Playgroud) 我有一个关于"元素不再附加到DOM"的问题.
我尝试了不同的解决方案,但他们间歇性地工作.请建议一个永久性的解决方案.
WebElement getStaleElemById(String id, WebDriver driver) {
try {
return driver.findElement(By.id(id));
} catch (StaleElementReferenceException e) {
System.out.println("Attempting to recover from StaleElementReferenceException ...");
return getStaleElemById(id, driver);
}
}
WebElement getStaleElemByCss(String css, WebDriver driver) {
try {
return driver.findElement(By.cssSelector(css));
} catch (StaleElementReferenceException e) {
System.out.println("Attempting to recover from StaleElementReferenceException ...");
return getStaleElemByCss(css, driver);
} catch (NoSuchElementException ele) {
System.out.println("Attempting to recover from NoSuchElementException ...");
return getStaleElemByCss(css, driver);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢,Anu
当我点击一个项目在web上打开时发生以下错误.我们中的任何人都知道解决方案吗?
错误:test_inline_edit_an_item_app_built_via_app_builder(TaskFeature):Capybara :: Poltergeist :: JavascriptError:页面上的Javascript代码中引发了一个或多个错误.如果您不关心这些错误,可以通过在Poltergeist配置中设置js_errors:false来忽略它们(有关详细信息,请参阅文档).
TypeError:'undefined'不是一个对象(评估't.subscribe'),地址是https://d3tga9h80dykic.cloudfront.net/assets/cd319648/podio-common-amd.js:1 /home/abhay/.rvm/gems /ruby-1.9.3-p362/gems/poltergeist-1.1.0/lib/capybara/poltergeist/browser.rb:197:in command'/home/abhay/.rvm/gems/ruby-1.9.3-p362/ gems/poltergeist-1.1.0/lib/capybara/poltergeist/browser.rb:42:infind'/home/abhay/.rvm/gems/ruby-1.9.3-p362/gems/poltergeist-1.1.0/lib/ capybara/poltergeist/driver.rb:110:在find'/home/abhay/.rvm/gems/ruby-1.9.3-p362/gems/capybara-2.0.2/lib/capybara/node/finders.rb:113 :incl in all'/home/abhay/.rvm/gems/ruby-1.9.3-p362/gems/capybara-2.0.2/lib/capybara/node/base.rb:78:in synchronize'/ home/abhay /.rvm/gems/ruby-1.9.3-p362/gems/capybara-2.0.2/lib/capybara/node/finders.rb:112:inall'/home/abhay/.rvm/gems/ruby-1.9. 3-p362/gems/capybara-2.0.2/lib/capybara/node/finders.rb:26:in block in find'/home/abhay/.rvm/gems/ruby-1.9.3-p362/gems/capybara -2.0.2/lib/capybara/node/base.rb:78:insynchronize'/ home/abhay/.rvm/gems/ruby-1.9.3-p362/gems/capybara-2.0.2/lib/capybara/node/finders.rb:26:in find'/home/abhay/.rvm/gems/ruby- 1.9.3-p362/gems/capybara-2.0.2/lib/capybara/session.rb:341:类中的inblock(2级):Session'/home/abhay/.rvm/gems/ruby-1.9.3- p362/gems/capybara-2.0.2/lib/capybara/dsl.rb:51:'task_feature.rb中的块(2级):489:inblock in test_inline_edit_an_item_app_built_via_app_builder'/ home/abhay/podio/auto_deetee/auto_deetee/test /test_helper.rb:69:in login_as'task_feature.rb:473:intest_inline_edit_an_item_app_built_via_app_builder'
1次测试,0次断言,0次失败,1次错误,0次跳过