当我试图运行此代码时,我无法找到任何web元素
package PremisesManagement;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class openbravo {
@Test
public void openbravoLoginTest() throws InterruptedException
{
System.setProperty("webdriver.chrome.driver", "C:\selenium\chromedriver.exe");
WebDriver d = new ChromeDriver();
d.get("http://119.81.222.91:8080/camps/security/Login_FS.html");
Thread.sleep(3000);
d.findElement(By.id("user")).sendKeys("xyz");
WebDriverWait wait = new WebDriverWait(d, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("//button[@id='buttonOK']")));
d.findElement(By.xpath("//button[@id='buttonOK']")).click();
}
}
实际定位的元素位于id为paramFrame1
的frame
内,因此您需要在查找元素之前切换此frame
:-
System.setProperty("webdriver.chrome.driver", "C:\selenium\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("http://119.81.222.91:8080/camps/security/Login_FS.html");
WebDriverWait wait = new WebDriverWait(driver, 10);
//First switch to frame with id paramFrame1
wait.until(ExpectedConditions.frameToBeAvailableAndSwitchToIt("paramFrame1"));
//Now find the element
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("user"))).sendKeys("xyz");
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("buttonOK"))).click();