Selenium With Java Cheat Sheet
Selenium With Java Cheat Sheet
driver.findElement(By.tagName
Switch to a frame using a WebElement:
By Tag Name: (<html tag name>)) WebElement iframe =
driver.findElement(By.cssSelector("#modal>iframe"));
driver.findElement(By.cssSelector(" driver.switchTo().frame(iframe);
By CSS Selector: Tag#Value of id attribute"))
Switch back to the main content:
driver.findElement(By.xpath
By XPath: (“//input[@type='submit']”)) driver.switchTo().defaultContent();
driver.findElement(By.linkText
By Link Text: (<link text>))
driver.findElement(By.partialLinkTe
Working with Files
By Partial Link Text: xt (<link text>))
Upload a file:
driver.findElement(By.id("file-
Driver Initialization
Chrome WebDriver driver = new ChromeDriver();
Note: Replace "x.y.z" with the version number of your Selenium Server
Selenium Operations
Standalone JAR file.
@BeforeClass executed once before class. Will execute after the execution of all
the test methods of available classes
Will execute before each test method runs @AfterTest belonging to that folder
@After The method with this annotation gets Will execute after the execution of all
executed after all the other tests are @AfterSuite the test methods in the suite
executed.
@AfterClass The method with this annotation gets
executed once after class.
@Ignore
Used to disable the tests from execution,
@Disabled but the corresponding reports of the tests
are still generated.