Created
September 1, 2022 22:02
-
-
Save eshnil2000/1bffb3bd366876fcf17c34d0b0684d69 to your computer and use it in GitHub Desktop.
selenium findElementbyID
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 newpackage; | |
import org.openqa.selenium.WebDriver; | |
import org.openqa.selenium.By; | |
//import org.openqa.selenium.firefox.FirefoxDriver; | |
//comment the above line and uncomment below line to use Chrome | |
import org.openqa.selenium.chrome.ChromeDriver; | |
public class MyClass { | |
public static void main(String[] args) { | |
// declaration and instantiation of objects/variables | |
//System.setProperty("webdriver.gecko.driver","C:\\geckodriver.exe"); | |
//WebDriver driver = new FirefoxDriver(); | |
//comment the above 2 lines and uncomment below 2 lines to use Chrome | |
System.setProperty("webdriver.chrome.driver","C:\\Users\\nnshah\\OneDrive - Intel Corporation\\Documents\\selenium-java-4.4.0\\chromedriver.exe"); | |
WebDriver driver = new ChromeDriver(); | |
String baseUrl = "http://demo.guru99.com/test/newtours/"; | |
baseUrl="https://demo.guru99.com/test/facebook.html"; | |
String expectedElement = "input"; | |
String actualElement = ""; | |
// launch Fire fox and direct it to the Base URL | |
driver.get(baseUrl); | |
// get the actual value of the title | |
//actualElement = driver.getTitle(); | |
actualElement= driver.findElement(By.id("email")).getTagName(); | |
System.out.println(actualElement); | |
/* | |
* compare the actual title of the page with the expected one and print | |
* the result as "Passed" or "Failed" | |
*/ | |
if (actualElement.contentEquals(expectedElement)){ | |
System.out.println("Test Passed!"); | |
} else { | |
System.out.println("Test Failed"); | |
} | |
//close Fire fox | |
driver.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment