java没有这样的元素异常,org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素:{“method”:“xpath”,“selector”...

这篇博客探讨了在自动化测试中验证登录过程的有效性和无效性,通过读取Excel文件进行不同组合的用户名和密码测试。代码示例展示了如何使用Selenium进行网页元素操作,但在登录成功时遇到了寻找错误元素的异常。博主寻求解决方案以正确处理登录成功的场景。
摘要由CSDN通过智能技术生成

我正在尝试使用所有有效和无效的输入验证登录部分 .

这是我试过的代码:

public void login_Valid_Invalid_Combinations() throws BiffException, IOException, InterruptedException

{

String FilePath = "D://credentials.xls";

FileInputStream FIS = new FileInputStream(FilePath);

Workbook WB = Workbook.getWorkbook(FIS);

Sheet SH = WB.getSheet(0);

for(int row =0; row<= SH.getRows()-1; row++)

{

String userNAME = SH.getCell(0, row).getContents();

String passWORD = SH.getCell(1, row).getContents();

System.out.println("USERMANE : "+userNAME + " PASSWORD : "+passWORD);

driver.get("LOGIN PAGE URL");

driver.findElement(By.id("Email")).sendKeys(userNAME);

driver.findElement(By.id("Password")).sendKeys(passWORD);

driver.findElement(By.id("btnlogin")).click();

System.out.println(driver.findElement(By.xpath("//*[@id='eError']")).getText());

Thread.sleep(2000);

String URL = driver.getCurrentUrl();

System.out.println(URL);

if (URL.equals("URL AFTER SUCCESFULL LOGIN"))

{

System.out.println("Login Successfull");

}

else

{

System.out.println("Login Failed");

}

}

driver.close();

}

我想在每次登录失败时显示错误消息,这很正常 . 但当 login is successful 具有有效输入时,它显示:

“org.openqa.selenium.NoSuchElementException:没有这样的元素:无法找到元素:{”method“:”xpath“,”selector“:”// * [@ id ='eError']“}”

因为错误消息未成功登录 .

你能帮我解决一下这个问题 .

情分析以下错误:Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"search-input"} Command duration or timeout: 3.97 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:54:28' System info: host: 'LAPTOP-34K1M0P4', ip: '192.168.32.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201' Driver info: org.openqa.selenium.firefox.FirefoxDriver Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=13.0.1, platform=XP, browserConnectionEnabled=true, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}] Session ID: 450cd28c-219b-444e-a9ff-427428c704f0 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method) at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62) at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45) at java.lang.reflect.Constructor.newInstance(Constructor.java:423) at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:193) at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:145) at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:573) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:326) at org.openqa.selenium.remote.RemoteWebDriver.findElementById(RemoteWebDriver.java:367) at org.openqa.selenium.By$ById.findElement(By.java:214) at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:318) at shiyan2.crawler.main(crawler.java:18) Caused by: org.openqa.selenium.remote.ErrorHandler$UnknownServerException: Unable to locate element: {"method":"id","selector":"search-input"} Build info: version: '2.40.0', revision: 'fbe29a9', time: '2014-02-19 20:54:28' System info: host: 'LAPTOP-34K1M0P4', ip: '192.168.32.1', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_201' Driver info: driver.version: unknown at <anonymous class>.<anonymous method>(file:///C:/Users/Y/AppData/Local/Temp/anonymous3190348505889140058webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:8904) at <anonymous class>.<anonymous method>(file:///C:/Users/Y/AppData/Local/Temp/anonymous3190348505889140058webdriver-profile/extensions/fxdriver@googlecode.com/components/driver_component.js:8913) at <anonymous class>.<anonymous method>(file:///C:/Users/Y/AppData/Local/Temp/anonymous3190348505889140058webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10878) at <anonymous class>.<anonymous method>(file:///C:/Users/Y/AppData/Local/Temp/anonymous3190348505889140058webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10883) at <anonymous class>.<anonymous method>(file:///C:/Users/Y/AppData/Local/Temp/anonymous3190348505889140058webdriver-profile/extensions/fxdriver@googlecode.com/components/command_processor.js:10825)
05-15
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值