【发布时间】:2014-10-16 18:24:50
【问题描述】:
我是 selenium 新手,写了一个基本测试来启动一个网站,点击链接,填写表格并提交。
一旦到达注册页面,它就无法找到“名字”文本框。我使用萤火虫仔细检查过,它只在一个地方可用。我什至尝试用 xpath 识别元素仍然得到相同的错误。
这是使用 xPath 识别名字文本框的代码。
package Default;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
//import org.openqa.selenium.firefox.FirefoxDriver;
public class FirstWDWithoutRecording {
@Test
public void SouthWestSignUp() throws InterruptedException
{
//Open the FF/Chrome browser
//FirefoxDriver oBrw = new FirefoxDriver();
ChromeDriver oBrw = new ChromeDriver();
//Maximize Browser
oBrw.manage().window().maximize();
//Open/Launch www.southwest.com
System.setProperty("webdriver.chrome.driver", "E://chromedriver.exe");
oBrw.get("http://www.southwest.com/");
//Click on Sign up and Save
//Recognising
oBrw.findElement(By.linkText("Sign up")).click();
Thread.sleep(7000);
//Enter First Name
oBrw.findElement(By.xpath("//input[@id='FIRST_NAME']")).clear();
oBrw.findElement(By.xpath("//input[@id='FIRST_NAME']")).sendKeys("abc");
//Enter Last Name
oBrw.findElement(By.id("LAST_NAME")).clear();
oBrw.findElement(By.id("LAST_NAME")).sendKeys("Kish123");
//Enter Email ID
oBrw.findElement(By.id("EMAIL")).clear();
oBrw.findElement(By.id("EMAIL")).sendKeys("abc@Kish123.com");
//Selecting Home Airport
Select uiHomeAp = new Select(oBrw.findElement(By.id("HOME_AIRPORT")));
uiHomeAp.deselectByVisibleText("Atlanta, GA - ATL");
//Accepting Conditions
oBrw.findElement(By.id("IAN")).click();
//Click Submit
oBrw.findElement(By.id("submit")).click();
}
}
【问题讨论】:
-
如果您将搜索直接应用到southwest.com/html/email/… 而不是从主页转发,会发生什么情况。这行得通吗?
-
不,它没有工作仍然得到同样的错误
标签: selenium xpath webdriver automated-tests