提交表单时,Selenium Send Keys无法与java一起使用 [英] Selenium Send Keys not Working with java while submitting a form
问题描述
使用locator方法(Xpath)提交表单时,我无法执行发送键操作.提交表单或登录时,我无法使用xpath找到该元素.
I am not able to perform the send keys operation while submitting a form using the locator method (Xpath). While submitting the forms or while login I am not able to find the element by using the 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).......
Also how do I find out the frame id as frame(0).......
http://www.ecomnets.com/careers/submit-a-resume /
我正在尝试填写此表单,但无法使用selenium命令填写详细信息.
I am trying to fill in this form and I am not able to fill in the details using the selenium commands.
推荐答案
页面的所有元素都位于iframe中,因此您必须首先切换到iframe:
All Elements of your page are within iframe so you have to first switch to iframe :
在登录前添加以下内容:
Add following before login :
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();
}
我刚刚检查了一下,它现在应该可以为您工作了.
I just checked , it should work now for you.
这篇关于提交表单时,Selenium Send Keys无法与java一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!