Created
January 18, 2022 16:21
-
-
Save muditlambda/b9e6530420a84678d45459b0b46581f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package LambdaTest; | |
import io.github.bonigarcia.wdm.WebDriverManager; | |
import org.openqa.selenium.By; | |
import org.openqa.selenium.WebElement; | |
import org.openqa.selenium.chrome.ChromeDriver; | |
import org.openqa.selenium.remote.DesiredCapabilities; | |
import org.openqa.selenium.remote.RemoteWebDriver; | |
import org.testng.Assert; | |
import org.testng.annotations.AfterTest; | |
import org.testng.annotations.BeforeTest; | |
import org.testng.annotations.Listeners; | |
import org.testng.annotations.Test; | |
import org.openqa.selenium.support.ui.Select; | |
import java.net.MalformedURLException; | |
import java.net.URL; | |
@Listeners({util.Listener.class}) | |
class AutomationUsingFindElement { | |
public String username = "YOUR USERNAME"; | |
public String accesskey = "YOUR ACCESSKEY"; | |
public static RemoteWebDriver driver = null; | |
public String gridURL = "@hub.lambdatest.com/wd/hub"; | |
@BeforeTest | |
public void setUp() throws Exception { | |
DesiredCapabilities capabilities = new DesiredCapabilities(); | |
capabilities.setCapability("browserName", "chrome"); | |
capabilities.setCapability("version", "96.0"); | |
capabilities.setCapability("platform", "win10"); // If this cap isn't specified, it will just get the any available one | |
capabilities.setCapability("build", "AutomationUsingFindElement"); | |
capabilities.setCapability("name", "AutomationUsingFindElementSuite"); | |
try { | |
driver = new RemoteWebDriver(new URL("https://" + username + ":" + accesskey + gridURL), capabilities); | |
} catch (MalformedURLException e) { | |
System.out.println("Invalid grid URL"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
} | |
@Test | |
public void findElementByName() { | |
try { | |
System.out.println("Logging into Lambda Test Input Form Demo Page"); | |
driver.get("https://www.lambdatest.com/selenium-playground/input-form-demo"); | |
WebElement nameTextBox = driver.findElement(By.name("name")); | |
nameTextBox.sendKeys("LambdaTest"); | |
System.out.println("Entered Name"); | |
WebElement emailTextBox = driver.findElement(By.name("email")); | |
emailTextBox.sendKeys("lambdatest@gmail.com"); | |
System.out.println("Entered Email"); | |
} catch (Exception e) { | |
} | |
} | |
@AfterTest | |
public void closeBrowser() { | |
driver.close(); | |
System.out.println("The driver has been closed."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment