Selenium在提交表单时发送不使用java的密钥
使用定位器方法(Xpath)提交表单时,我无法执行发送密钥操作。在提交表单或登录时,我无法使用xpath找到元素Selenium在提交表单时发送不使用java的密钥,java,forms,selenium,xpath,Java,Forms,Selenium,Xpath,使用定位器方法(Xpath)提交表单时,我无法执行发送密钥操作。在提交表单或登录时,我无法使用xpath找到元素 package accomplishment_Tracker; import java.util.concurrent.TimeUnit; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; imp
package accomplishment_Tracker;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.firefox.FirefoxProfile;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;
public class ects {
public WebDriver driver;
@BeforeTest
public void openurl(){
//driver =new FirefoxDriver();
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.setPreference("reader.parse-on-load.enabled",false);
driver = new FirefoxDriver(firefoxProfile);
driver.get("http://66.192.160.50/ects/");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
System.out.println("Website opened succesfully");
}
//LOGIN
@Test
public void login(){
driver.findElement(By.xpath("html/body/div[1]/div/div/div/div[2]/form/fieldset/div[1]/input")).sendKeys("abcde");//("admin");
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/div[2]/input")).sendKeys("password");
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/div[3]/label/input")).click();
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/input")).click();
}
@AfterTest
public void close(){
driver.quit();
}
}
另外,如何找到帧id作为帧(0)
我正在尝试填写此表单,但无法使用selenium命令填写详细信息。您页面的所有元素都在iframe中,因此您必须首先切换到iframe: 登录前添加以下内容:
driver.switchTo().frame(0);
因此,它将是:
public void login(){
driver.switchTo().frame(0);
driver.findElement(By.xpath("html/body/div[1]/div/div/div/div[2]/form/fieldset/div[1]/input")).sendKeys("abcde");//("admin");
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/div[2]/input")).sendKeys("password");
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/div[3]/label/input")).click();
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/input")).click();
}
我刚刚检查过,现在应该可以使用了。您页面的所有元素都在iframe中,因此您必须首先切换到iframe: 登录前添加以下内容:
driver.switchTo().frame(0);
因此,它将是:
public void login(){
driver.switchTo().frame(0);
driver.findElement(By.xpath("html/body/div[1]/div/div/div/div[2]/form/fieldset/div[1]/input")).sendKeys("abcde");//("admin");
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/div[2]/input")).sendKeys("password");
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/div[3]/label/input")).click();
driver.findElement(By.xpath("/html/body/div[1]/div/div/div/div[2]/form/fieldset/input")).click();
}
我刚检查过,现在应该对你有用了。很高兴帮助你…:)很高兴帮助你…:)