使用定位器方法(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;
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为frame(0).......
http://www.ecomnets.com/careers/submit-a-resume/
我正在尝试填写此表单,但无法使用 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();
}
我刚刚检查过,它现在应该适合你了。
关于java - 提交表单时,Selenium 发送 key 无法使用 java,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31959659/