小编Hem*_*nth的帖子

如果元素不存在,则isElementPresent非常慢.

我使用下面的代码来检查我的网页上的元素

private boolean isElementPresent(By by) {
try {       
      driver.findElement(by);
      return true;
    } catch (NoSuchElementException e) {
        return false;
    }
    catch (Exception e)
    {       
        return false;
    }

  }
Run Code Online (Sandbox Code Playgroud)

如果特定区域出现在结果中,我需要检查我的程序,如下所示

isElementPresent(By.xpath(".//*[@id='header']")));
Run Code Online (Sandbox Code Playgroud)

如果存在,则此功能快速完成,但如果不存在,则运行很长时间.

有人可以帮我解决这个问题,以便快速执行此检查吗?

selenium webdriver selenium-webdriver

18
推荐指数
1
解决办法
1万
查看次数

某些浏览器在Selenium 2中找不到会话错误

如果这个问题含糊不清,我很抱歉,但我有一套Selenium WebDriver测试,他们目前无法在Chrome或IE中使用.无论出于何种原因,Firefox工作正常

Chrome和IE的错误非常相似,而且令人费解,因为我确信Chrome测试之前已经有效.

(是的,我确实在路径中有chromedriver,它正在打开浏览器).

基本上会发生的是,测试将在中途运行,甚至能够与页面进行交互.

但最终,它们都会因此错误而失败:

     org.openqa.selenium.WebDriverException: 

     session 2fca1234-343f-45e7-af49-6486b13e1eba does not exist
Run Code Online (Sandbox Code Playgroud)

我只是想知道是否有其他人看到过这个错误或类似的东西.

我已经看了很多,并没有发现任何人有同样的问题.

为了记录,我正在使用Java运行我的测试并使用Selenium 2.5

selenium-webdriver

10
推荐指数
1
解决办法
1万
查看次数

使用selenium hd在play框架测试中设置会话cookie

我正在尝试使用selenium hd进行一些单元测试.我目前有以下代码:

    browser.goTo("http://localhost:3333/")
    browser.$("#email").text("michele@sample.com")
    browser.$("#password").text("secret")
    browser.$("#loginbutton").click()
    browser.goTo("http://localhost:3333/michele")
Run Code Online (Sandbox Code Playgroud)

但我希望能够设置会话cookie,而不是每次测试都必须这样做.

我试着这样做

    browser.webDriver.manage().addCookie( new Cookie("PLAY_SESSION",
      "1dd6811c9df64e03a892f55f57dd0f1190656d88-email%3Amichele%40sample.com") )
Run Code Online (Sandbox Code Playgroud)

但是没有成功,因为当我尝试使用browser.getCookie("PLAY_SESSION").getValue()must contains 检索cookie时,我得到一个空指针异常 ("michele@sample.com")

任何帮助是极大的赞赏!!

testing scala playframework-2.0 selenium-webdriver

5
推荐指数
1
解决办法
781
查看次数

页面刷新期间selenium.common.exceptions.StaleElementReferenceException

页面包含一些数据(包含少量行的表).有"刷新"按钮可以重新加载和重绘页面上的一些元素,而无需重新加载静态数据(ajax).

我正在尝试为该页面创建正确的测试,但有时会收到StaleElementReferenceException.

我的代码(python):

from selenium import webdriver
browser=webdriver.Firefox()
browser.get('http://mytisite')
browser.implicitly_wait(10)
browser.find_element_by_id('start').click()
while browser.find_element_by_id('status').text!='Done':
    browser.find_element_by_id('refresh').click()
    for row in browser.find_elements_by_class_name('datarow'):
        if not is_correct(row.text):
           print "incorrect"
    time.sleep(10)
Run Code Online (Sandbox Code Playgroud)

5次迭代中的1次失败就行"if not is_correct(row.text)":

selenium.common.exceptions.StaleElementReferenceException: 
 Message: u'Element not found in the cache - perhaps the page 
 has changed since it was looked up' ; Stacktrace: Method 
 fxdriver.cache.getElementAt threw an error in 
 resource://fxdriver/modules/web_element_cache.js 
Run Code Online (Sandbox Code Playgroud)

主要问题:页面已包含以前的数据,所以我在ajax刷新和webdriver的元素查询之间进行竞争find_elements_by_class_name('datarow').

我怎样才能正确解决ajax refresh和webdriver之间的竞争?谢谢.

selenium webdriver

5
推荐指数
1
解决办法
1万
查看次数

如何获得由AlarmManager设置的下一个闹钟时间设置方法

我正在设置这样的警报

  AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

  alarm.setRepeating(AlarmManager.RTC_WAKEUP,enter code here
        calendar1.getTimeInMillis(), 24*60*60 * 1000, pintent);
Run Code Online (Sandbox Code Playgroud)

我正在使用它来获得下一个闹钟时间,但它给了我默认设备alarmApp的下一个闹钟时间.

     android.provider.Settings.System.getString(
                getContentResolver(),
                android.provider.Settings.System.NEXT_ALARM_FORMATTED)
Run Code Online (Sandbox Code Playgroud)

那么怎么办才能得到我设定的下一个闹钟........

android

5
推荐指数
1
解决办法
1805
查看次数

在CQ5中发布新页面的问题

我在我的电脑上安装了CQ5.5 authorpublish实例.但是当我添加新页面并将其发布时,它不会出现在发布实例中.仅呈现空白页面.

我试过在工具中siteadminReplication页面和页面激活它.只有导航项出现在"发布"实例中.

我也检查了请求日志.但它只给出了一个

200 response(OK) 
Run Code Online (Sandbox Code Playgroud)

有人可以帮我这个吗?

aem

4
推荐指数
1
解决办法
3712
查看次数

条件jsf包括

如何在运行时有条件地包含jsf facelets文件?所需的示例功能是

if ( add button click) {

ui:include src="Add.xhtml"
}

if ( update button click) {

ui:include src="Update.xhtml"
}
Run Code Online (Sandbox Code Playgroud)

上面的语法只是指示性的......

Mojarra 2.1.1/Apache Tomcat 7.0.22/PrimeFaces 3.4

user-interface dynamic include jsf-2

4
推荐指数
1
解决办法
9081
查看次数

oracle.jdbc.driver.T4CConnection无法强制转换为oracle.jdbc.OracleConnection

WrappedConnectionJDK6 wrapped = (WrappedConnectionJDK6) dbStrategy.getConnection();
            Connection underlyingConn = wrapped.getUnderlyingConnection();
            OracleConnection oracleConn = (OracleConnection)underlyingConn;
Run Code Online (Sandbox Code Playgroud)

最后一行给出错误 -

> ERROR
> [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/web].[resteasy-servlet]]
> (http-/0.0.0.0:8080-1) Servlet.service() for servlet resteasy-servlet
> threw exception: org.jboss.resteasy.spi.UnhandledException:
> java.lang.ClassCastException: oracle.jdbc.driver.T4CConnection cannot
> be cast to oracle.jdbc.OracleConnection
Run Code Online (Sandbox Code Playgroud)

jdbc-odbc jboss6.x

4
推荐指数
1
解决办法
8346
查看次数

java.lang.NullPointerException webdriver

我是使用webdriver进行自动测试的新手.有人请检查我收到的原因

java.lang.NullPointerException
    at SuccessfullHoverTestCib.testSuccessfullHoverTestCib
    (SuccessfullHoverTestCib.java:29)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source).....
Run Code Online (Sandbox Code Playgroud)

我正在运行以下代码:

public class SuccessfullHoverTestCib {
    private WebDriver driver;
    private String baseUrl;
    private StringBuffer verificationErrors = new StringBuffer();

    @Before
    public void setUp() throws Exception {
        File pathToFirefoxBinary = new File("C:\\Documents and Settings\\chakarova\\Local Settings\\Application Data\\Mozilla Firefox\\firefox.exe");  
        FirefoxBinary firefoxbin = new FirefoxBinary(pathToFirefoxBinary);
        WebDriver driver = new FirefoxDriver(firefoxbin,null); 
        baseUrl = "http://cibnew.sofia.ifao.net:7001/cib_web/web";
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
    }

    @Test
    public void testSuccessfullHoverTestCib() throws Exception {
        driver.get(baseUrl);
        driver.findElement(By.id("inputButton")).click();
        driver.findElement(By.linkText("Hotels")).click();
        driver.findElement(By.id("pageLink_57")).click();
    }

    @After …
Run Code Online (Sandbox Code Playgroud)

firefox webdriver selenium-webdriver

3
推荐指数
1
解决办法
8188
查看次数

如何将Scalatest与硒整合

通过阅读http://www.scalatest.org/user_guide/using_selenium,我正在尝试整合硒和scalatest硒DSL。

这是我正在使用的代码:

class BlogSpec extends FlatSpec with ShouldMatchers with Chrome {


    System.setProperty("webdriver.chrome.driver", "C:\\selenium-drivers\\chromedriver.exe"); 
    val host = "http://www.google.com"

    go to (host)
    title should be ("Awesome Blog")

}
Run Code Online (Sandbox Code Playgroud)

但我收到此错误:

*运行中止* java.lang.IllegalStateException:驱动程序可执行文件的路径必须由webdriver.chrome.driver系统属性设置;有关更多信息,请参见 http://code.google.com/p/selenium/wiki/ChromeDriver。可以从 org.openqa.selenium上的com.google.common.base.Preconditions.checkState(Preconditions.java:176)上的http://code.google.com/p/chromedriver/downloads/list下载最新版本 。 org.openqa.selenium.chrome.ChromeDriverService.createDefaultService(ChromeDriverService.java:61)上的org.openqa.selenium.chrome.ChromeDriver。(ChromeDriver.java:107)上的remote.service.DriverService.findExecutable(DriverService.java:118) ),位于org.scalatest.selenium.Chrome $ class。$ init $(WebBrowser.scala:3756)
在BlogSpec。(BlogSpec.scala:12)在sun.reflect.NativeConstructorAccessorImpl.newInstance0(本机方法)在sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)在sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.newjava: 27)在java.lang.reflect.Constructor.newInstance(Constructor.java:513)
...

该驱动程序确实存在C:\\selenium-drivers\\chromedriver.exe吗?我是否正确设置了驱动程序,或者上述代码中是否存在单独的问题?Chrome也无法启动

selenium scala scalatest

3
推荐指数
1
解决办法
3119
查看次数