Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Java中使用Selenium提交表单_Java_Selenium_Selenium Webdriver_Selenium Chromedriver - Fatal编程技术网

如何在Java中使用Selenium提交表单

如何在Java中使用Selenium提交表单,java,selenium,selenium-webdriver,selenium-chromedriver,Java,Selenium,Selenium Webdriver,Selenium Chromedriver,我正在使用seleniumwebdriver自动化系统。语言是Java。大部分事情我都做了,但有一点我被卡住了。我需要提交一份包含用户名、密码和重新输入密码字段的表单。但是,当我填充它们(使用selenium)并单击“创建帐户”按钮时,它不起作用 这是密码 我用这些方法提交表格。但没有一个成功 从Inspect元素获取的表单HTML 创建一个Steam帐户名 可用帐户名 请选择一个或使用您选择的其他名称重试 选择一个密码 重新输入密码 我还需要说,当我手动单击创建帐户按钮时,它正在工

我正在使用
seleniumwebdriver
自动化系统。语言是
Java
。大部分事情我都做了,但有一点我被卡住了。我需要提交一份包含用户名、密码和重新输入密码字段的表单。但是,当我填充它们(使用selenium)并单击“创建帐户”按钮时,它不起作用

这是密码

我用这些方法提交表格。但没有一个成功

从Inspect元素获取的表单HTML


创建一个Steam帐户名

可用帐户名

请选择一个或使用您选择的其他名称重试 选择一个密码 重新输入密码

我还需要说,当我手动单击
创建帐户按钮时,它正在工作。但使用selenium时,它不起作用,请传递此消息

您选择的帐户名不可用。请选择 另一个名字。您输入的密码是不允许的。请选择一个 不同的密码,至少包含8个字符

但是用户名和密码可以。没问题。因为当我 如果正在使用该用户名和密码,请手动单击它。


我过去也有过类似的问题,有时候关注不同的元素会有所帮助,然后点击

首先,我要把重点放在

编辑:

您说它是手动工作的,所以我建议您使用
操作
如下:

Actions action = new Actions(driver);
WebElement btnElement=driver.findElement(By.xpath("//a[@id='createAccountButton']"));
action.doubleClick(btnElement).build().perform();
但可能是你的系统真的有缺陷

编辑2:

Selenium的最佳实践是将
WebDriverWait
ExpectedConditions
一起使用:

WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id("createAccountButton")));
见和

我认为这应该可以做到


希望这对您有所帮助。

不要单击.xpath(“//a[@id='createAccountButton']/span”)
并提交表单,单击用户名、密码或确认密码字段,然后单击enter

 System.setProperty("webdriver.chrome.driver", "./ChromeDriver/chromedriver.exe");

 WebDriver driver = new ChromeDriver();
 driver.get("URL Here");

 WebElement element9 = driver.findElement(By.id("accountname"));
 element9.sendKeys(username);

 WebElement element10 = driver.findElement(By.id("password"));
 element10.sendKeys(password);

 WebElement element12 = driver.findElement(By.id("reenter_password"));
 element12.sendKeys(password);

 element12.click();
 element12.submit();

@MosheSlavin我不知道有很多元素,我只是添加了这些字段。我需要添加整个HTML表单元素吗?@MosheSlavin我添加了整个HTML元素。你能查一下吗?@BaruchG。但我可以看到用户名和密码正在该字段中键入。它会抛出一个错误
元素。。。在点处不可单击
否安全气囊系统这也不起作用。但是谢谢你的帮助。你看到鼠标移到按钮并点击了吗?还是没用?就是odd@HansanaAthukorala你从我这里得到+1!这是一个难题!;)我已经更新了问题的最后部分。你能检查一下吗?我已经解决了这个问题。但是谢谢你的回答。
Actions action = new Actions(driver);
WebElement btnElement=driver.findElement(By.xpath("//a[@id='createAccountButton']"));
action.doubleClick(btnElement).build().perform();
WebDriverWait wait = new WebDriverWait(webDriver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(By.id("createAccountButton")));
 System.setProperty("webdriver.chrome.driver", "./ChromeDriver/chromedriver.exe");

 WebDriver driver = new ChromeDriver();
 driver.get("URL Here");

 WebElement element9 = driver.findElement(By.id("accountname"));
 element9.sendKeys(username);

 WebElement element10 = driver.findElement(By.id("password"));
 element10.sendKeys(password);

 WebElement element12 = driver.findElement(By.id("reenter_password"));
 element12.sendKeys(password);

 element12.click();
 element12.submit();