Creating A Selenium Script
Creating A Selenium Script
driver.get("https://google.com");
driver.findElement(By.xpath("//*[@id='lst-ib']")).sendKeys("Fresco Play");
This study source was downloaded by 100000815997471 from CourseHero.com on 12-19-2021 09:15:51 GMT -06:00
https://www.coursehero.com/file/95282284/Creating-a-Selenium-Scriptdocx/
driver.findElement(By.xpath("//*[@id='lst-ib']")).sendKeys(Keys.ENTER);
Thread.sleep(5000);
System.out.println("Page Title : " + driver.getTitle());
driver.findElement(By.xpath("//*[@id='rso']/div/div/div[2]/div/div/h3/a")).
click();
Thread.sleep(5000);
System.out.println("Page Title : " + driver.getTitle());
driver.quit();
Locate Elements
Most important step in test automation is to identify the web page elements
accurately. Selenium Webdriver performs it with help of
***findElement()***&***findElements()***.
Types of XPath
Element Locators help to find the element on the web pages accurately. Let’s start
with Syntax XPath. It can be written in two types as below.
Xpath=//tagname[@attribute='value']
This study source was downloaded by 100000815997471 from CourseHero.com on 12-19-2021 09:15:51 GMT -06:00
https://www.coursehero.com/file/95282284/Creating-a-Selenium-Scriptdocx/
Absolute XPath - It will be in long, and you can see HTML DOM Structure which
will be followed by single (/).
/html/body/div/selection/div[2]/div/div/input[1]
**Relative XPath– It will be short, and it will start in the middle of the HTML
DOM Structure which will be followed by double (//).
//input[@value='Google Search']
This study source was downloaded by 100000815997471 from CourseHero.com on 12-19-2021 09:15:51 GMT -06:00
https://www.coursehero.com/file/95282284/Creating-a-Selenium-Scriptdocx/
Powered by TCPDF (www.tcpdf.org)