在執行我的測試腳本時觀察以下錯誤。有人能幫助我找出失敗的原因嗎?NoSuchElementException當執行我的測試腳本時
org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"id","selector":"lid"}
Command duration or timeout: 20.45 seconds
這是我的代碼的片段。請注意,元素存在於同一幀中,因此不需要幀交換。元素的
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.support.ui.ExpectedConditions;
//import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.Test;
public class LoginPage
{
@Test
public void testLoginFail()
{
WebDriver driver = new FirefoxDriver();
driver.get("https://www.zoho.com/crm/");
driver.manage().timeouts().implicitlyWait(20,TimeUnit.SECONDS);
driver.findElement(By.linkText("LOGIN")).click();
//WebDriverWait wait = new WebDriverWait(driver,40);
//wait.until(ExpectedConditions.visibilityOfElementLocated((By.id("lid"))));
driver.findElement(By.id("lid")).sendKeys("[email protected]");
HTML的觀點是:
<input name="lid" id="lid" class="input usrbx" value="" onkeypress="clearmsg()" type="email">
你試過包裝'driver.findElement(By.id(「lid」))。sendKeys(「[email protected]」);''顯式等待'中的語句嗎?另外附上登錄表單HTML,人們將很難幫助你。我會做的是打開瀏覽器控制檯,並嘗試查看用'.val()'填充輸入的選擇器。 (例如''('#lid')。val(「[email protected]」)')。如果它與控制檯JQuery協同工作,它將與你的選擇器一起工作。 :) – iamdanchiv
我已經嘗試用明確的等待包裝這個語句,但它沒有奏效。 – Dks
@Dks你有沒有試過我的解決方案? –