WebDriver driver=new FirefoxDriver(); Thread.sleep(3000); driver.get("https://www.google.com/gmail/about/"); driver.manage().timeouts().pageLoadTimeout(40,TimeUnit.SECONDS); //Clicking on Create account linkdriver.findElement(By.xpath("//a[@href='https://accounts.google.com/SignUp?service=mail&continue=http%3A%2F%2Fmail.google.com%2Fmail%2F%3Fpc%3Dcarousel-about-en']")).click(); driver.manage().timeouts().pageLoadTimeout(40,TimeUnit.SECONDS); Assert.assertTrue(driver.findElement(By.xpath("//input[@name='firstName']")).isDisplayed()); 線程“主”org.openqa.selenium.NoSuchElementException 中的異常:無法找到元素://input[@name='firstName']如何解決這個問題?
2 回答

陪伴而非守候
TA貢獻1757條經驗 獲得超8個贊
看起來您的xpath可能是錯誤的。代替:
//input[@name='firstName']
嘗試使用:
//*[@id='firstName']
作為xpath。
您可以通過轉到檢查元素,右鍵單擊元素并從“復制”子菜單中選擇選項來 在 Chrome 上找到xpath 。
Copy XPath

白板的微信
TA貢獻1883條經驗 獲得超3個贊
這是時間問題,表單需要一兩秒鐘才能加載。您可以添加顯式等待以等待它
WebDriverWait wait = new WebDriverWait(WebDriverRefrence, 10);
WebElement firstName = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("firstName")));
Assert.assertTrue(firstName.isDisplayed());
添加回答
舉報
0/150
提交
取消