[英]In Selenium Webdriver, click button once the text is entered in text box
I am trying to build a Selenium Automation framework for Gmail. 我正在尝试为Gmail构建Selenium自动化框架。 I have installed below tools: JDK, Eclipse, Selenium Jars, Gradle, TestNG
我安装了以下工具:JDK,Eclipse,Selenium Jars,Gradle,TestNG
I am trying to login to gmail. 我正在尝试登录gmail。 But i cam getting below error by the time i enter my username.
但是当我输入用户名时,我会低于错误。 Its trying to click "Next" button before username is entered.
它尝试在输入用户名之前单击“下一步”按钮。
Can I use wait
where ever required while developing framework? 我可以在开发框架时使用
wait
地方吗? Do I need to maintain any standards while calling wait
. 在呼叫
wait
我是否需要保持任何标准。 Write any user defined wait
methods. 编写任何用户定义的
wait
方法。
Error: FAILED: gmailLoginShouldBeSuccessful org.openqa.selenium.ElementNotVisibleException: Cannot click on element (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 207 milliseconds 错误:FAILED:gmailLoginShouldBeSuccessful org.openqa.selenium.ElementNotVisibleException:无法单击元素(警告:服务器未提供任何堆栈跟踪信息)命令持续时间或超时:207毫秒
My Code: 我的代码:
@Test
public void gmailLoginShouldBeSuccessful(){
//1.Go to Gmail website
System.setProperty("webdriver.ie.driver", "C:\\Selenium_Softwares_Docs_Videos\\IEDriverServer_x64_3.1.0\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver();
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.get("http://gmail.com");
//2.Fill in username
WebElement userTextBox = driver.findElement(By.id("Email"));
userTextBox.clear();
userTextBox.sendKeys("xxxx");
//3. click on next button
WebElement nxtBtn = driver.findElement(By.id("next"));
nxtBtn.click();
//4.Fill in password
WebElement pwdTextBox = driver.findElement(By.id("Passwd-hidden"));
userTextBox.clear();
userTextBox.sendKeys("xxxxxxx");
//5.Click sign in
WebElement signBtn = driver.findElement(By.id("signIn"));
signBtn.click();
}
You can use explicit wait to achieve your requirement. 您可以使用显式等待来满足您的要求。
WebDriverWait wait = new WebDriverWait(yourWebDriver, 5);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//xpath_to_element")));
Webdriver will wait for 5 seconds for your element to be able to be clicked. Webdriver将等待5秒钟,以便能够单击您的元素。
Use Chrome Driver instead of internet Explorer: 使用Chrome驱动程序代替Internet Explorer:
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
import org.testng.annotations.Test;
public class TestCommons {
@Test
public void gmailLoginShouldBeSuccessful() throws InterruptedException {
// 1.Go to Gmail website
System.setProperty("webdriver.chrome.driver", System.getProperty("user.dir") + "\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.manage().window().maximize();
driver.get("http://gmail.com");
// 2.Fill in username
driver.findElement(By.id("Email")).clear();
driver.findElement(By.id("Email")).sendKeys("vishala");
// 3. click on next button
driver.findElement(By.id("next")).click();
// 4.Fill in password
driver.findElement(By.id("Passwd")).sendKeys("vishala");
// 5.Click sign in
driver.findElement(By.id("signIn")).click();
driver.quit();
}
}
Hope this will work for you :) 希望这对你有用:)
您是否可以发送RETURN键而不是单击“登录”按钮?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.