【发布时间】:2016-12-07 20:32:02
【问题描述】:
在 google 和 StackOverflow 上进行大量研发后,我发布了这个查询..
我想只使用类名在 Facebook 上输入用户名和密码,我不想为此使用类型、名称、id .. 我尝试了所有可能的选项,但没有运气有人能提供解决方案。
这是我的代码..
package login;
import org.testng.annotations.Test;
import java.util.concurrent.TimeUnit;
import org.testng.annotations.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class MercuryLogin1 {
private WebDriver driver;
private String baseUrl;
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
System.setProperty("webdriver.chrome.driver","C:\\Automation_Info\\Selenium\\chromedriver_win32\\chromedriver.exe");
System.setProperty("webdriver.gecko.driver", "C:\\Automation_Info\\Selenium\\geckodriver-v0.9.0-win64\\geckodriver.exe");
driver = new ChromeDriver();
baseUrl = "http://facebook.com/";
//driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
}
@Test
public void testMercuryLogin1() throws Exception {
driver.get(baseUrl + "/");
driver.findElement(By.xpath("//input[@class=inputtext][0]")).sendKeys("tutorial");
driver.findElement(By.xpath("//input[@class='nputtext][1]")).sendKeys("tutorial");
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
//driver.quit();
}
}
【问题讨论】:
标签: selenium login webdriver classname