简体   繁体   English

为什么我的Selenium和Java基本程序无法正常工作?

[英]Why doesn't my basic program through Selenium and Java works?

I used the code below to login into amazon website and it works but somehow its not identifying the element for password. 我使用下面的代码登录到亚马逊网站,它可以工作,但是以某种方式无法识别密码元素。

driver.get("accounts@gmail.com");
WebElement signIn = driver.findElement(By.id("Email"));
signIn.sendKeys("XXX@gmail.com");
signIn.submit();
WebElement pwd = driver.findElement(By.id("Passwd"));
pwd.sendKeys("password");
pwd.submit();

Within driver.get() line instead of your EmailID you need to pass the relevant amazon url as an example https://www.amazon.com/ . driver.get()行中,而不是您的EmailID您需要传递相关的亚马逊URL作为示例https://www.amazon.com/

So instead of: 所以代替:

driver.get("accounts@gmail.com");

You would like to: 你想要...吗:

driver.get("https://www.amazon.com/");
  1. To run the code, place a valid URL in the statement driver.get(<URL>) . 要运行代码,请将有效的URL放入语句driver.get(<URL>) For Example: driver.get("www.amazon.com) . This will successfully open the Amazon site in whichever browser your driver is trying to open 例如: driver.get("www.amazon.com) 。这将成功在驱动程序尝试打开的浏览器中打开Amazon网站。

2.You have mentioned in a comment as "code is failing for sending value to password field". 2.您在注释中提到“代码无法将值发送到密码字段”。 I would suggest you to write an Xpath for it, if the id locator isn't working. 如果ID定位器不起作用,我建议您为此编写一个Xpath。

However, if you want the people to help you out more, please place the HTML code of your page and also error received, it will be easy to debug and also to provide accurate answer. 但是,如果您想让人们更多地帮助您,请放置页面的HTML代码以及收到的错误,这将很容易调试并提供准确的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如果我通过phpMyAdmin执行查询,则它在我的Java程序中不存在时仍然有效 - If I execute my query through phpMyAdmin it works while it doesn't in my java program 我的Java程序为什么不将String写入文件? - Why doesn't my Java program write String into file? 我的程序有时有效,有时却无效 - My program sometimes works and sometimes it doesn't Scene Builder预览不适用于我的Java程序(基本计算器) - Scene Builder preview doesn't apply to my Java program (basic calculator) 我的Java程序不会遍历整个CSV文件 - My Java program doesn't iterate through my entire CSV file 程序在单步执行时有效,但在运行时不运行 - program works when stepping through but doesn't when running 为什么我的第二个形状没有出现在使用 awt 的 JAVA 程序中? - Why doesn't my 2nd shape appear in my JAVA program using awt? 为什么我不能使用 selenium 将图像上传到上传输入按钮? 手动打开时它工作正常,但为什么它不能通过 selenium 工作? - why cannot i upload an image to an upload input button using selenium? It works fine when opened manually but why doesn't it work through selenium? 我不明白为什么我的 Java 程序无法运行 - I don't understand why my Java program doesn't run 该命令在终端上有效,但在Java程序中不起作用 - The command works on terminal but doesn't work in java program
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM