我正在尝试在gmail中打开邮件以验证“www.gmail.com”上的链接,并且已经从“www.abc.com”进行了注册,那么我们如何使用selenium WebDriver以关键字驱动来识别邮件框架。
我在一个方法中创建了两个方法,它包含所有带有操作的关键字,另一个方法包含位置。
但是无论何时执行,我都无法点击邮件进行打开,因为在WebElement中它会变为空。
那么,任何人都可以检查我是否正确声明了语法?或者为什么我没有得到价值?
以下是代码:
Exception occurred operateWebDriverThe given selector /html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div[2]/div[1]/div[1]/div/div/div[7]/div/div[1]/div[2]/div/table/tbody/tr[ is either invalid or does not result in a WebElement. The following error occurred:
InvalidSelectorError: Unable to locate an element with the xpath expression /html/body/div[7]/div[3]/div/div[2]/div[1]/div[2]/div/div/div/div[2]/div[1]/div[1]/div/div/div[7]/div/div[1]/div[2]/div/table/tbody/tr[ because of the following error:
[Exception... "The expression is not a legal expression." code: "12" nsresult: "0x805b0033 (SyntaxError)" location: "file:///C:/DOCUME~1/Chayan/LOCALS~1/Temp/anonymous1831932369561342639webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js Line: 5934"]
Command duration or timeout: 16 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '2.41.0', revision: '3192d8a', time: '2014-03-27 17:18:15'
System info: host: 'aa-ff7b4a68', ip: '192.168.1.3', os.name: 'Windows XP', os.arch: 'x86', os.version: '5.1', java.version: '1.7.0_71'
Session ID: 051985f9-6320-4d0f-ad48-0ab3ff975f02
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{platform=XP, acceptSslCerts=true, javascriptEnabled=true, cssSelectorsEnabled=true, databaseEnabled=true, browserName=firefox, handlesAlerts=true, browserConnectionEnabled=true, webStorageEnabled=true, nativeEvents=false, rotatable=false, locationContextEnabled=true, applicationCacheEnabled=true, takesScreenshot=true, version=18.0}]
Taking Screen Shot
错误:
{{1}}
答案 0 :(得分:0)
您可以使用公共类xY a4W
找到所有邮件,然后点击索引
List<WebElement> mails = driver.findElements(By.cssSelector(".xY.a4W")); // finds the mail body
mails.get(0).click(); // open first mail
您还可以找到来自特定发件人的所有邮件
String name = "name";
List<WebElement> mails = driver.findElements(By.xpath("//*[@class='zF'][@name='" + name + "']/../..");
mails.get(0).click();
这将打开名为&#34; name&#34;。
的第一封邮件答案 1 :(得分:0)
我已经使用此代码从gmail获取密码 但是你需要更新xpath(检查一次)
WebElement tableelement=DriverObj.findElement(By.xpath("//div[@class='Cp']/div/table//tbody"));
java.util.List<WebElement> tableelement1=tableelement.findElements(By.xpath("//div[@class='Cp']/div/table//tbody/tr"));
int tableelementsize=tableelement1.size();
int i;
if(tableelementsize>0){
//DriverObj.navigate().refresh();
for(i=0;i<tableelementsize;i++){
DriverObj.findElement(By.xpath("//div[@class='Cp']/div/table//tbody/tr/td[6]")).click();
}
}else {
if(tableelementsize==0){
DriverObj.navigate().refresh();
for(i=0;i<tableelementsize;i++){
DriverObj.findElement(By.xpath("//div[@class='Cp']/div/table//tbody/tr/td[6]")).click();
}
}
}