使用Firefox或Chrome驱动程序时,代码工作正常。我只在使用IE时遇到此问题。我的代码的Prt如下所述:
我的代码如下:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.annotations.Test;
public class Hover {
@Test()
public void testHover() throws InterruptedException{
WebDriver driver;
String ieDriverPath = System.getenv("webdriver.ie.driver");
System.setProperty("webdriver.ie.driver", ieDriverPath);
driver = new InternetExplorerDriver();
driver.navigate();
driver.get("https://test.xxxxx.com/");
Thread.sleep(5000);
WebElement txtboxusername = driver.findElement(By.xpath("//*[@id='logonId']"));
WebElement txtboxpassword = driver.findElement(By.xpath("//*[@id='logonPassword']"));
WebElement btnsubmit = driver
.findElement(By
.xpath("/html/body/div[2]/div[3]/div/form/fieldset/ol/li[2]/input[4]"));
txtboxusername.sendKeys("username");
txtboxpassword.sendKeys("password");
btnsubmit.submit();
}
}
我的HTML代码:
</fieldset>>
<ol>
<li>
<label forname="emailaddress">
<input id="logonId" width="200" type="text" onchange="javascript:this.value = this.value.toLowerCase();" onfocus="this.onkeypress = pressEnter;" onkeypress="" value="" style="width: 200px;" size="30" name="logonId">
</li>
<li>
<label forname="password">
<input id="logonPassword" width="200" type="password" alt="You can find your temporary password in the 'password assistance' email." onfocus="this.onkeypress = pressEnter;" style="width: 200px;" size="30" name="logonPassword">
<input id="logonPasswordOld" type="hidden" value="" name="logonPasswordOld">
<br>
<label> </label>
<img class="buttonImg" src="/wcsstore/images/common/button_left.gif">
<input class="buttonSubmit" type="button" onclick="javascript:submitForm document.LogonForm)" value="Go" name="button">
<img class="buttonImg" src="/wcsstore/images/common/button_right.gif">
</li>
<li>
<li> </li>
</ol>
</fieldset>
我只添加了一些我认为有用的HTML代码。