我正在使用selenium 2.33(eclipse),我正试图通过以下选项之一从网站上获取字符串(几个单词):
vendorTitle = driver.findElement(By.xpath("//a[@id='Result_1']/strong[2]")).getText();
OR
vendorTitle = driver.findElement(By.xpath("//a[@id='Result_1']")).getText();
OR
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]”
提前致谢!
答案 0 :(得分:0)
Use below command
vendorTitle = driver.findElement(By.xpath("//a[@id='Result_1']").getAttribute("title")));
You will get the data based on getAttribute
.