Best Selenium code snippet using org.openqa.selenium.By.id
Source:NLPerfectoWebDriver.java
2 * Copyright (c) 2016, Neotys3 * All rights reserved.4 *5 * Redistribution and use in source and binary forms, with or without6 * modification, are permitted provided that the following conditions are met:7 *8 * * Redistributions of source code must retain the above copyright9 * notice, this list of conditions and the following disclaimer.10 * * Redistributions in binary form must reproduce the above copyright11 * notice, this list of conditions and the following disclaimer in the12 * documentation and/or other materials provided with the distribution.13 * * Neither the name of Neotys nor the names of its contributors may be14 * used to endorse or promote products derived from this software15 * without specific prior written permission.16 *17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED19 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE20 * DISCLAIMED. IN NO EVENT SHALL NEOTYS BE LIABLE FOR ANY21 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES22 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;23 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND24 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS26 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.27 */28package com.neotys.selenium.proxies;29import java.util.List;30import java.util.Set;31import java.util.logging.Level;32import org.openqa.selenium.By;33import org.openqa.selenium.Capabilities;34import org.openqa.selenium.OutputType;35import org.openqa.selenium.WebDriverException;36import org.openqa.selenium.WebElement;37import org.openqa.selenium.interactions.Keyboard;38import org.openqa.selenium.interactions.Mouse;39import org.openqa.selenium.remote.CommandExecutor;40import org.openqa.selenium.remote.ErrorHandler;41import org.openqa.selenium.remote.FileDetector;42import org.openqa.selenium.remote.RemoteWebDriver;43import org.openqa.selenium.remote.SessionId;44import com.neotys.selenium.proxies.helpers.WrapperUtils;45public class NLPerfectoWebDriver extends NLRemoteWebDriver{46 47 private final RemoteWebDriver remoteWebDriver;48 private final NLWebDriver webDriver;49 private final WrapperUtils wrapperUtils;50 51 public NLPerfectoWebDriver(final RemoteWebDriver originalWebDriver, final NLWebDriver webDriver,52 final WrapperUtils wrapperUtils) {53 this.remoteWebDriver = originalWebDriver;54 this.webDriver = webDriver;55 this.wrapperUtils = wrapperUtils;56 }57 58 /**59 * @return60 * @see java.lang.Object#hashCode()61 */62 @Override63 public int hashCode() {64 return webDriver.hashCode();65 }66 /**67 * @param obj68 * @return69 * @see java.lang.Object#equals(java.lang.Object)70 */71 @Override72 public boolean equals(Object obj) {73 return webDriver.equals(obj);74 }75 /**76 * @param detector77 * @see org.openqa.selenium.remote.RemoteWebDriver#setFileDetector(org.openqa.selenium.remote.FileDetector)78 */79 @Override80 public void setFileDetector(FileDetector detector) {81 remoteWebDriver.setFileDetector(detector);82 }83 /**84 * @return85 * @see org.openqa.selenium.remote.RemoteWebDriver#getSessionId()86 */87 @Override88 public SessionId getSessionId() {89 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.getSessionId());90 }91 /**92 * @return93 * @see org.openqa.selenium.remote.RemoteWebDriver#getErrorHandler()94 */95 @Override96 public ErrorHandler getErrorHandler() {97 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.getErrorHandler());98 }99 /**100 * @param handler101 * @see org.openqa.selenium.remote.RemoteWebDriver#setErrorHandler(org.openqa.selenium.remote.ErrorHandler)102 */103 @Override104 public void setErrorHandler(ErrorHandler handler) {105 remoteWebDriver.setErrorHandler(handler);106 }107 /**108 * @return109 * @see org.openqa.selenium.remote.RemoteWebDriver#getCommandExecutor()110 */111 @Override112 public CommandExecutor getCommandExecutor() {113 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.getCommandExecutor());114 }115 /**116 * @return117 * @see org.openqa.selenium.remote.RemoteWebDriver#getCapabilities()118 */119 @Override120 public Capabilities getCapabilities() {121 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.getCapabilities());122 }123 /**124 * @param url125 * @see org.openqa.selenium.remote.RemoteWebDriver#get(java.lang.String)126 */127 @Override128 public void get(String url) {129 webDriver.get(url);130 }131 /**132 * @return133 * @see org.openqa.selenium.remote.RemoteWebDriver#getTitle()134 */135 @Override136 public String getTitle() {137 return webDriver.getTitle();138 }139 /**140 * @return141 * @see org.openqa.selenium.remote.RemoteWebDriver#getCurrentUrl()142 */143 @Override144 public String getCurrentUrl() {145 return webDriver.getCurrentUrl();146 }147 /**148 * @param outputType149 * @return150 * @throws WebDriverException151 * @see org.openqa.selenium.remote.RemoteWebDriver#getScreenshotAs(org.openqa.selenium.OutputType)152 */153 @Override154 public <X> X getScreenshotAs(OutputType<X> outputType) throws WebDriverException {155 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.getScreenshotAs(outputType));156 }157 /**158 * @param by159 * @return160 * @see org.openqa.selenium.remote.RemoteWebDriver#findElements(org.openqa.selenium.By)161 */162 @Override163 public List<WebElement> findElements(By by) {164 return webDriver.findElements(by);165 }166 /**167 * @param by168 * @return169 * @see org.openqa.selenium.remote.RemoteWebDriver#findElement(org.openqa.selenium.By)170 */171 @Override172 public WebElement findElement(By by) {173 return webDriver.findElement(by);174 }175 /**176 * @param using177 * @return178 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementById(java.lang.String)179 */180 @Override181 public WebElement findElementById(String using) {182 return webDriver.findElement(By.id(using));183 }184 /**185 * @param using186 * @return187 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementsById(java.lang.String)188 */189 @Override190 public List<WebElement> findElementsById(String using) {191 return webDriver.findElements(By.id(using));192 }193 /**194 * @param using195 * @return196 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementByLinkText(java.lang.String)197 */198 @Override199 public WebElement findElementByLinkText(String using) {200 return webDriver.findElement(By.linkText(using));201 }202 /**203 * @param using204 * @return205 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementsByLinkText(java.lang.String)206 */207 @Override208 public List<WebElement> findElementsByLinkText(String using) {209 return webDriver.findElements(By.linkText(using));210 }211 /**212 * @param using213 * @return214 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementByPartialLinkText(java.lang.String)215 */216 @Override217 public WebElement findElementByPartialLinkText(String using) {218 return webDriver.findElement(By.partialLinkText(using));219 }220 /**221 * @param using222 * @return223 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementsByPartialLinkText(java.lang.String)224 */225 @Override226 public List<WebElement> findElementsByPartialLinkText(String using) {227 return webDriver.findElements(By.partialLinkText(using));228 }229 /**230 * @param using231 * @return232 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementByTagName(java.lang.String)233 */234 @Override235 public WebElement findElementByTagName(String using) {236 return webDriver.findElement(By.tagName(using));237 }238 /**239 * @param using240 * @return241 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementsByTagName(java.lang.String)242 */243 @Override244 public List<WebElement> findElementsByTagName(String using) {245 return webDriver.findElements(By.tagName(using));246 }247 /**248 * @param using249 * @return250 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementByName(java.lang.String)251 */252 @Override253 public WebElement findElementByName(String using) {254 return webDriver.findElement(By.name(using));255 }256 /**257 * @param using258 * @return259 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementsByName(java.lang.String)260 */261 @Override262 public List<WebElement> findElementsByName(String using) {263 return webDriver.findElements(By.name(using));264 }265 /**266 * @param using267 * @return268 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementByClassName(java.lang.String)269 */270 @Override271 public WebElement findElementByClassName(String using) {272 return webDriver.findElement(By.className(using));273 }274 /**275 * @param using276 * @return277 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementsByClassName(java.lang.String)278 */279 @Override280 public List<WebElement> findElementsByClassName(String using) {281 return webDriver.findElements(By.className(using));282 }283 /**284 * @param using285 * @return286 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementByCssSelector(java.lang.String)287 */288 @Override289 public WebElement findElementByCssSelector(String using) {290 return webDriver.findElement(By.cssSelector(using));291 }292 /**293 * @param using294 * @return295 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementsByCssSelector(java.lang.String)296 */297 @Override298 public List<WebElement> findElementsByCssSelector(String using) {299 return webDriver.findElements(By.cssSelector(using));300 }301 /**302 * @param using303 * @return304 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementByXPath(java.lang.String)305 */306 @Override307 public WebElement findElementByXPath(String using) {308 return webDriver.findElement(By.xpath(using));309 }310 /**311 * @param using312 * @return313 * @see org.openqa.selenium.remote.RemoteWebDriver#findElementsByXPath(java.lang.String)314 */315 @Override316 public List<WebElement> findElementsByXPath(String using) {317 return webDriver.findElements(By.xpath(using));318 }319 /**320 * @return321 * @see org.openqa.selenium.remote.RemoteWebDriver#getPageSource()322 */323 @Override324 public String getPageSource() {325 return webDriver.getPageSource();326 }327 /**328 * 329 * @see org.openqa.selenium.remote.RemoteWebDriver#close()330 */331 @Override332 public void close() {333 webDriver.close();334 }335 /**336 * 337 * @see org.openqa.selenium.remote.RemoteWebDriver#quit()338 */339 @Override340 public void quit() {341 webDriver.quit();342 }343 /**344 * @return345 * @see org.openqa.selenium.remote.RemoteWebDriver#getWindowHandles()346 */347 @Override348 public Set<String> getWindowHandles() {349 return webDriver.getWindowHandles();350 }351 /**352 * @return353 * @see org.openqa.selenium.remote.RemoteWebDriver#getWindowHandle()354 */355 @Override356 public String getWindowHandle() {357 return webDriver.getWindowHandle();358 }359 /**360 * @param script361 * @param args362 * @return363 * @see org.openqa.selenium.remote.RemoteWebDriver#executeScript(java.lang.String, java.lang.Object[])364 */365 @Override366 public Object executeScript(String script, Object... args) {367 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.executeScript(script, args));368 }369 /**370 * @param script371 * @param args372 * @return373 * @see org.openqa.selenium.remote.RemoteWebDriver#executeAsyncScript(java.lang.String, java.lang.Object[])374 */375 @Override376 public Object executeAsyncScript(String script, Object... args) {377 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.executeAsyncScript(script, args));378 }379 /**380 * @return381 * @see org.openqa.selenium.remote.RemoteWebDriver#switchTo()382 */383 @Override384 public TargetLocator switchTo() {385 return webDriver.switchTo();386 }387 /**388 * @return389 * @see org.openqa.selenium.remote.RemoteWebDriver#navigate()390 */391 @Override392 public Navigation navigate() {393 return webDriver.navigate();394 }395 /**396 * @return397 * @see org.openqa.selenium.remote.RemoteWebDriver#manage()398 */399 @Override400 public Options manage() {401 return webDriver.manage();402 }403 /**404 * @param level405 * @see org.openqa.selenium.remote.RemoteWebDriver#setLogLevel(java.util.logging.Level)406 */407 @Override408 public void setLogLevel(Level level) {409 remoteWebDriver.setLogLevel(level);410 }411 /**412 * @return413 * @see org.openqa.selenium.remote.RemoteWebDriver#getKeyboard()414 */415 @Override416 public Keyboard getKeyboard() {417 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.getKeyboard());418 }419 /**420 * @return421 * @see org.openqa.selenium.remote.RemoteWebDriver#getMouse()422 */423 @Override424 public Mouse getMouse() {425 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.getMouse());426 }427 /**428 * @return429 * @see org.openqa.selenium.remote.RemoteWebDriver#getFileDetector()430 */431 @Override432 public FileDetector getFileDetector() {433 return wrapperUtils.wrapIfNecessary(webDriver, remoteWebDriver.getFileDetector());434 }435 /**436 * @return437 * @see org.openqa.selenium.remote.RemoteWebDriver#toString()438 */439 @Override440 public String toString() {441 return webDriver.toString();442 }443 @Override444 public void startTransaction(final String name) {445 webDriver.startTransaction(name);446 }447 @Override448 public void stopTransaction() {449 webDriver.stopTransaction();450 }451 @Override452 public void setCustomName(final String name) {453 webDriver.setCustomName(name);454 }455 @Override456 public String getRegexToCleanURLs() {457 return webDriver.getRegexToCleanURLs();458 }459}...
Source:Amajon1.java
...61 // String TestClassName="TC147_Amazon";62 63 64 @Test65 public static void setBaseURL(){66 67 68 // OpenBrowser();69 //HelloSignIn();70 // Login();71 // Logout();72 // CloseBrowser() ;73 74 }75 public static void OpenBrowser() 76 {77 78 System.setProperty("webdriver.chrome.driver",driverPath);79 driver = new ChromeDriver(); 80 driver.get(baseUrl);81 driver.manage().window().maximize() ; 82 83 84 }85 86 87 public static void CloseBrowser() 88 {89 90 driver.quit();91 92 try {93 ExcelApiTest3 eat = new ExcelApiTest3();94 eat.PassPutCellData("E://Regression1.xls","Sheet1",6,3, "PASS");95 } catch (Exception e) {96 // TODO Auto-generated catch block97 e.printStackTrace();98 }99 100 101 102 }103 104 public static void HelloSignIn()105 {106 107 Actions actions = new Actions(driver);108 WebElement ele=driver.findElement(By.xpath("//*[text()='Hello. Sign in']"));109 new WebDriverWait(driver, 990000000).until(ExpectedConditions.visibilityOf(ele)); 110 actions.moveToElement(ele).click().build().perform();111 112 }113 114 public static void Login()115 {116 driver.findElement(By.xpath(" //input[@type='email' and @maxlength='128' and @id='ap_email' and @name='email']")).sendKeys("sudhakarth2008@gmail.com");117 driver.findElement(By.xpath("//*[@id=\"continue\"]")).click();118 driver.findElement(By.xpath("//*[@id=\"ap_password\"]")).sendKeys("babli1234");119 driver.findElement(By.xpath("//*[@id='signInSubmit']")).click();120 }121 122 public static void Logout()123 {124 125 Actions actions = new Actions(driver);126 WebElement ele1=driver.findElement(By.xpath("//*[@id='nav-link-yourAccount']/span[2]"));127 new WebDriverWait(driver, 990000000).until(ExpectedConditions.visibilityOf(ele1)); 128 actions.moveToElement(ele1).perform();129 WebElement ele2=driver.findElement(By.xpath("//*[text()='Sign Out']"));130 new WebDriverWait(driver, 1990000000).until(ExpectedConditions.visibilityOf(ele2)); 131 actions.moveToElement(ele2).click().build().perform();132 }133 134}...
Source:Amazon.java
...61 // String TestClassName="TC147_Amazon";62 63 64 @Test65 public static void setBaseURL(){66 67 68 OpenBrowser();69 HelloSignIn();70 Login();71 Logout();72 CloseBrowser() ;73 74 }75 public static void OpenBrowser() 76 {77 78 System.setProperty("webdriver.chrome.driver",driverPath);79 driver = new ChromeDriver(); 80 driver.get(baseUrl);81 driver.manage().window().maximize() ; 82 83 84 }85 86 87 public static void CloseBrowser() 88 {89 90 driver.quit();91 92 /*try {93 ExcelApiTest3 eat = new ExcelApiTest3();94 eat.PassPutCellData("E://Regression1.xls","Sheet1",4,3, "PASS");95 } catch (Exception e) {96 e.printStackTrace();97 }*/98 99 100 101 }102 103 public static void HelloSignIn()104 {105 106 Actions actions = new Actions(driver);107 WebElement ele=driver.findElement(By.xpath("//*[text()='Hello. Sign in']"));108 new WebDriverWait(driver, 990000000).until(ExpectedConditions.visibilityOf(ele)); 109 actions.moveToElement(ele).click().build().perform();110 111 }112 113 public static void Login()114 {115 driver.findElement(By.xpath(" //input[@type='email' and @maxlength='128' and @id='ap_email' and @name='email']")).sendKeys("sudhakarth2008@gmail.com");116 driver.findElement(By.xpath("//*[@id=\"continue\"]")).click();117 driver.findElement(By.xpath("//*[@id=\"ap_password\"]")).sendKeys("babli1234");118 driver.findElement(By.xpath("//*[@id='signInSubmit']")).click();119 }120 121 public static void Logout()122 {123 124 Actions actions = new Actions(driver);125 WebElement ele1=driver.findElement(By.xpath("//*[@id='nav-link-yourAccount']/span[2]"));126 new WebDriverWait(driver, 990000000).until(ExpectedConditions.visibilityOf(ele1)); 127 actions.moveToElement(ele1).perform();128 WebElement ele2=driver.findElement(By.xpath("//*[text()='Sign Out']"));129 new WebDriverWait(driver, 1990000000).until(ExpectedConditions.visibilityOf(ele2)); 130 actions.moveToElement(ele2).click().build().perform();131 }132 133}...
Source:Amajon2.java
...55 String driverPath = "C:\\Users\\sudhakar\\Desktop\\seleni\\chromedriver_win32\\chromedriver.exe";56 public WebDriver driver ; 57 58 @Test59 public void b_verifyHomepageTitle() throws Exception{60 61 }62 63 64 65 @BeforeTest66 public void setBaseURL(){67 68 69 System.setProperty("webdriver.chrome.driver",driverPath);70 driver = new ChromeDriver(); 71 72 73 driver.get(baseUrl);74 75 driver.manage().window().maximize() ;76 77 78 79 Actions actions = new Actions(driver);80 WebElement ele=driver.findElement(By.xpath("//*[text()='Hello. Sign in']"));81 new WebDriverWait(driver, 990000000).until(ExpectedConditions.visibilityOf(ele)); 82 83 84 85 actions.moveToElement(ele).click().build().perform();86 87 88 driver.findElement(By.xpath(" //input[@type='email' and @maxlength='128' and @id='ap_email' and @name='email']")).sendKeys("sudhakarth2008@gmail.com");89 driver.findElement(By.xpath("//*[@id=\"continue\"]")).click();90 driver.findElement(By.xpath("//*[@id=\"ap_password\"]")).sendKeys("babli1234");91 driver.findElement(By.xpath("//*[@id='signInSubmit']")).click();92 93 WebElement ele1=driver.findElement(By.xpath("//*[@id='nav-link-yourAccount']/span[2]"));94 new WebDriverWait(driver, 990000000).until(ExpectedConditions.visibilityOf(ele1)); 95actions.moveToElement(ele1).perform();96WebElement ele2=driver.findElement(By.xpath("//*[text()='Sign Out']"));97 new WebDriverWait(driver, 1990000000).until(ExpectedConditions.visibilityOf(ele2)); 98 actions.moveToElement(ele2).click().build().perform();99 100 101 }102 @AfterTest103 public void afterTest() {104 105 106 driver.quit();107 108 }109 110}...
Source:Signinpage.java
...54 public String baseUrl = "https://www.facebook.com/";55 String driverPath = "C:\\Users\\sudhakar\\Desktop\\seleni\\chromedriver_win32\\chromedriver.exe";56 public WebDriver driver ; 57 @Test58 public void b_verifyHomepageTitle() throws Exception{59 60 //driver.findElement(By.xpath(" ")).sendKeys(" ");61 ////driver.findElement(By.xpath(" ")).click();62 63 driver.findElement(By.xpath(" //*[@id='email'] ")).sendKeys("sudhakarth2009@gmail.com");64 driver.findElement(By.xpath("//*[@id='pass']")).sendKeys("babli12345");65 driver.findElement(By.xpath("//input[@value='Log In' and @aria-label='Log In']")).click();66 try {67 Thread.sleep(6000);68 } catch (InterruptedException e) {69 e.printStackTrace();70 }71 72 driver.findElement(By.xpath("//*[@id='pageLoginAnchor']")).click();73 74 try {75 Thread.sleep(3000);76 } catch (InterruptedException e) {77 e.printStackTrace();78 }79 80 driver.findElement81 (By.xpath("//li[@class='_54ni navSubmenu _6398 _64kz __MenuItem' and @role='presentation']")).click();82 83 } // Ends Before Test 84 85 86 87 88 //Starts Before Test89 @BeforeTest90 public void setBaseURL()91 {92 ChromeOptions options = new ChromeOptions();93 options.addArguments("--disable-notifications");94 System.setProperty("webdriver.chrome.driver",driverPath);95 driver =new ChromeDriver(options);96 driver.get(baseUrl);97 driver.manage().window().maximize() ;98 99 100 }101 102 //Actions actions = new Actions(driver);103 104 105 @AfterTest106 public void afterTest() {107 driver.quit(); 108 }109 110 } ...
Source:Facebook.java
...54 public String baseUrl = "https://www.facebook.com/";55 String driverPath = "C:\\Users\\sudhakar\\Desktop\\seleni\\chromedriver_win32\\chromedriver.exe";56 public WebDriver driver ; 57 @Test58 public void b_verifyHomepageTitle() throws Exception{59 60 //driver.findElement(By.xpath(" ")).sendKeys(" ");61 ////driver.findElement(By.xpath(" ")).click();62 63 driver.findElement(By.xpath(" //*[@id='email'] ")).sendKeys("sudhakarth2009@gmail.com");64 driver.findElement(By.xpath("//*[@id='pass']")).sendKeys("babli12345");65 driver.findElement(By.xpath("//input[@value='Log In' and @aria-label='Log In']")).click();66 try {67 Thread.sleep(6000);68 } catch (InterruptedException e) {69 e.printStackTrace();70 }71 72 driver.findElement(By.xpath("//*[@id='pageLoginAnchor']")).click();73 74 try {75 Thread.sleep(3000);76 } catch (InterruptedException e) {77 e.printStackTrace();78 }79 80 driver.findElement81 (By.xpath("//li[@class='_54ni navSubmenu _6398 _64kz __MenuItem' and @role='presentation']")).click();82 83 } // Ends Before Test 84 85 86 87 88 //Starts Before Test89 @BeforeTest90 public void setBaseURL()91 {92 ChromeOptions options = new ChromeOptions();93 options.addArguments("--disable-notifications");94 System.setProperty("webdriver.chrome.driver",driverPath);95 driver =new ChromeDriver(options);96 driver.get(baseUrl);97 driver.manage().window().maximize() ;98 99 100 }101 102 //Actions actions = new Actions(driver);103 104 105 @AfterTest106 public void afterTest() {107 driver.quit(); 108 }109 110 } ...
Source:Amajon.java
...53 String driverPath = "C:\\Users\\sudhakar\\Desktop\\seleni\\chromedriver_win32\\chromedriver.exe";54 public WebDriver driver ; 55 // starts Before Class 56 @BeforeTest57 public void setBaseURL() {58 59 System.setProperty("webdriver.chrome.driver",driverPath);60 driver = new ChromeDriver(); 61 driver.get(baseUrl);62 driver.manage().window().maximize() ;63 64 Actions actions = new Actions(driver); 65 66 WebElement ele=driver.findElement(By.xpath("//*[text()='Hello. Sign in']"));67 new WebDriverWait(driver, 990000000).until(ExpectedConditions.visibilityOf(ele)); 68 actions.moveToElement(ele).click().build().perform();69 70 driver.findElement71 (By.xpath(" //input[@type='email' and @maxlength='128' and @id='ap_email' and @name='email']"))72 .sendKeys("sudhakarth2008@gmail.com");73 driver.findElement(By.xpath("//*[@id=\"continue\"]")).click();74 driver.findElement(By.xpath("//*[@id=\"ap_password\"]")).sendKeys("babli1234");75 driver.findElement(By.xpath("//*[@id='signInSubmit']")).click();76 77 WebElement ele1=driver.findElement(By.xpath("//*[@id='nav-link-yourAccount']/span[2]"));78 new WebDriverWait(driver, 990000000).until(ExpectedConditions.visibilityOf(ele1)); 79 actions.moveToElement(ele1).perform();80 WebElement ele2=driver.findElement(By.xpath("//*[text()='Sign Out']"));81 new WebDriverWait(driver, 1990000000).until(ExpectedConditions.visibilityOf(ele2)); 82 actions.moveToElement(ele2).click().build().perform();83 84 }// Ends Before Class 85 @AfterTest86 public void afterTest() {87 driver.quit();88 }89 90 }...
Source:MyStepdefs.java
...23import static org.junit.Assert.assertTrue;24public class MyStepdefs {25 WebDriver driver = new WebDriverGerencia().createWebDriver(DriverManagerType.CHROME);26 @io.cucumber.java.pt.Dado("^que eu acesse a página da VV Test$")27 public void queEuAcesseAPáginaDaVVTest() {28 driver.get("https://bit.ly/3jOMrR9");29 }30 @io.cucumber.java.pt.E("^acesse o menu \"([^\"]*)\"$")31 public void acesseOMenu(String arg0) throws Throwable {32 driver.findElement(By.cssSelector("#menu-item-226 > a")).click();33 }34 @io.cucumber.java.pt.Quando("^eu preencher todos os campos obrigatórios$")35 public void euPreencherTodosOsCamposObrigatórios() {36 driver.findElement(By.id("nf-field-5")).sendKeys("Diego");37 driver.findElement(By.id("nf-field-6")).sendKeys("Conrado");38 driver.findElement(By.id("nf-field-7")).sendKeys("diguers@gmail.com");39 driver.findElement(By.id("nf-field-8")).sendKeys("diguers@gmail.com");40 driver.findElement(By.id("nf-field-17")).sendKeys("11941045821");41 driver.findElement(By.id("nf-label-class-field-10-1")).click();42 new Select(driver.findElement(By.id("nf-field-11"))).selectByVisibleText("mais de 5 anos");43 new Select(driver.findElement(By.id("nf-field-12"))).selectByVisibleText("Sou mega chato");44 driver.findElement(By.id("nf-label-class-field-13-0")).click();45 driver.findElement(By.name("nf-field-14")).sendKeys("C#,Java e Ruby");46 driver.findElement(By.name("nf-field-15")).sendKeys("C#,Java e Ruby");47 }48 @io.cucumber.java.pt.Então("^deve ser direcionado para uma página de sucesso$")49 public void deveSerDirecionadoParaUmaPáginaDeSucesso() {50 driver.findElement(By.id("nf-field-16")).click();51 driver.manage().timeouts().implicitlyWait(50000, TimeUnit.SECONDS);52 //WebElement TxtBoxContent = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div/main/article/div/div/div/div/div[1]/p"));53 //System.out.print(TxtBoxContent.getText());54 String actualString = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div/div/main/article/div/div/div/div/div[1]/p")).getText();55 System.out.print(actualString);56 Assert.assertTrue(actualString.contains("Your form has been successfully submitted."));57 driver.quit();58 }59}...
id
Using AI Code Generation
1[INFO] --- maven-compiler-plugin:3.1:compile (default-compile) @ selenium ---2[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ selenium ---3[INFO] --- maven-compiler-plugin:3.1:testCompile (default-testCompile) @ selenium ---4[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ selenium ---5[INFO] --- maven-jar-plugin:2.4:jar (default-jar) @ selenium ---6[INFO] --- maven-assembly-plugin:2.4:single (default) @ selenium ---
id
Using AI Code Generation
1driver.findElement(By.id("id")).click();2driver.findElement(By.name("name")).click();3driver.findElement(By.className("class")).click();4driver.findElement(By.linkText("link text")).click();5driver.findElement(By.partialLinkText("partial link text")).click();6driver.findElement(By.tagName("tag name")).click();7driver.findElement(By.xpath("xpath")).click();8driver.findElement(By.cssSelector("css selector")).click();
id
Using AI Code Generation
1WebElement username = driver.findElement(By.id("username"));2WebElement password = driver.findElement(By.name("password"));3WebElement login = driver.findElement(By.className("login"));4WebElement button = driver.findElement(By.tagName("button"));5WebElement forgotPassword = driver.findElement(By.linkText("Forgot Password?"));6WebElement forgot = driver.findElement(By.partialLinkText("Forgot"));7WebElement password = driver.findElement(By.cssSelector("input[type='password']"));8WebElement username = driver.findElement(By.id("username"));9WebElement password = username.findElement(By.name("password"));10WebElement login = password.findElement(By.className("login"));11WebElement button = login.findElement(By.tagName("button"));12WebElement forgotPassword = button.findElement(By.linkText("Forgot Password?"));13WebElement forgot = forgotPassword.findElement(By.partialLinkText("Forgot"));14WebElement password = username.findElement(By.cssSelector("input[type='password']"));15List<WebElement> links = driver.findElements(By.tagName("a"));16WebElement body = driver.findElement(By.tagName("body
id
Using AI Code Generation
1By searchButton = By.id("searchButton");2By searchText = By.name("searchText");3By termsOfService = By.linkText("Terms of Service");4By terms = By.partialLinkText("Terms");5By div = By.tagName("div");6By searchButton = By.className("searchButton");
LambdaTest’s Selenium 4 tutorial is covering every aspects of Selenium 4 testing with examples and best practices. Here you will learn basics, such as how to upgrade from Selenium 3 to Selenium 4, to some advanced concepts, such as Relative locators and Selenium Grid 4 for Distributed testing. Also will learn new features of Selenium 4, such as capturing screenshots of specific elements, opening a new tab or window on the browser, and new protocol adoptions.
Upgrading From Selenium 3 To Selenium 4?: In this chapter, learn in detail how to update Selenium 3 to Selenium 4 for Java binding. Also, learn how to upgrade while using different build tools such as Maven or Gradle and get comprehensive guidance for upgrading Selenium.
What’s New In Selenium 4 & What’s Being Deprecated? : Get all information about new implementations in Selenium 4, such as W3S protocol adaption, Optimized Selenium Grid, and Enhanced Selenium IDE. Also, learn what is deprecated for Selenium 4, such as DesiredCapabilites and FindsBy methods, etc.
Selenium 4 With Python: Selenium supports all major languages, such as Python, C#, Ruby, and JavaScript. In this chapter, learn how to install Selenium 4 for Python and the features of Python in Selenium 4, such as Relative locators, Browser manipulation, and Chrom DevTool protocol.
Selenium 4 Is Now W3C Compliant: JSON Wireframe protocol is retiring from Selenium 4, and they are adopting W3C protocol to learn in detail about the advantages and impact of these changes.
How To Use Selenium 4 Relative Locator? : Selenium 4 came with new features such as Relative Locators that allow constructing locators with reference and easily located constructors nearby. Get to know its different use cases with examples.
Selenium Grid 4 Tutorial For Distributed Testing: Selenium Grid 4 allows you to perform tests over different browsers, OS, and device combinations. It also enables parallel execution browser testing, reads up on various features of Selenium Grid 4 and how to download it, and runs a test on Selenium Grid 4 with best practices.
Selenium Video Tutorials: Binge on video tutorials on Selenium by industry experts to get step-by-step direction from automating basic to complex test scenarios with Selenium.
LambdaTest also provides certification for Selenium testing to accelerate your career in Selenium automation testing.
Get 100 minutes of automation test minutes FREE!!