猿问

线程“主”org.openqa.selenium.NoSuchElementException

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 link

driver.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']


如何解决这个问题?


繁花不似锦
浏览 117回答 2
2回答

陪伴而非守候

看起来您的xpath可能是错误的。代替://input[@name='firstName']尝试使用://*[@id='firstName']作为xpath。您可以通过转到检查元素,右键单击元素并从“复制”子菜单中选择选项来 在 Chrome 上找到xpath 。Copy XPath

白板的微信

这是时间问题,表单需要一两秒钟才能加载。您可以添加显式等待以等待它WebDriverWait wait = new WebDriverWait(WebDriverRefrence, 10);WebElement firstName = wait.until(ExpectedConditions.presenceOfElementLocated(By.name("firstName")));Assert.assertTrue(firstName.isDisplayed()); 
随时随地看视频慕课网APP

相关分类

Java
我要回答