java - 提交表单时,Selenium 发送 key 无法使用 java

标签 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;
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/

相关文章:

java - 与 artemis 一起使用的瓦片 map 的数据结构

java - 跨 c 请求属性 :import contexts

jquery - 如果使用 jquery 选择下拉项,则显示表单字段

jquery - 使用 jQuery 对充当 Radio 的按钮进行 Bootstrap3 表单验证

asp.net - 如何使用 Selenium RC 运行 Google Chrome?

java - 使用RC4加密和解密

java - SimpleJdbcCall 不适用于存储函数

php - 实体选择列表形式的其他

javascript - 如何点击javascript javascript :__doPostBack ('ac$w$PC$PC$grid' ,'Page$2' )

python - Selenium 超时异常 python