首页 文章

尝试按元素获取字符串时的selenium异常

提问于
浏览
-1

我正在使用selenium 2.33(eclipse),我正试图通过以下选项之一从网站获取字符串(几个单词):

vendorTitle = driver.findElement(By.xpath("//a[@id='Result_1']/strong[2]")).getText();

要么

vendorTitle = driver.findElement(By.xpath("//a[@id='Result_1']")).getText();

要么

vendorTitle = driver.findElement(By.id("Result_1")).getText();

但是得到以下例外:

错误:org.openqa.selenium.NoSuchElementException:无法找到元素:{“method”:“xpath”,“selector”:“// a [@ id ='Result_1']”}命令持续时间或超时:16毫秒有关此错误的文档,请访问:http://seleniumhq.org/exceptions/no_such_element.html构建信息:版本:'2.33.0',修订版:'4ecaf82108b2a6cc6f006aae81961236eba93358',时间:'2013-05-22 12:00 :17'系统信息:os.name:'Windows 7',os.arch:'amd64',os.version:'6.1',java.version:'1.6.0_38'会话ID:15fff09c-3758-479e-bd5c -da15b13c8fd4驱动程序信息:org.openqa.selenium.firefox.FirefoxDriver功能[{platform = XP,acceptSslCerts = true,javascriptEnabled = true,browserName = firefox,rotate = false,locationContextEnabled = true,version = 21.0,cssSelectorsEnabled = true,databaseEnabled = true,handlesAlerts = true,browserConnectionEnabled = true,nativeEvents = true,webStorageEnabled = true,applicationCacheEnabled = true,takesScreenshot = true}]

我做错了什么吗?

(我通过selenium IDE收集了元素“// a [@ id ='Result_1'] / strong [2]”

提前致谢!

1 回答

  • 0

    使用以下命令

    vendorTitle = driver.findElement(By.xpath("//a[@id='Result_1']").getAttribute("title")));
    

    您将获得基于 getAttribute 的数据 .

相关问题