Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 6

AGENDA

RECAP Last Session


Module 538 – Mouse Hover
Module 539 – Finding Links
Module 540 & 541 – Browse Methods
Module 542 – POM (page object model)
Module 543 – TestNG Parameters
Find All Links

•Open URL and inspect the desired element.

•List<WebElement> allURLss = driver.findElements(By.tagName("a")); In this we will


get list of WebElements with tagname 'a'. Collect all URLs
•Traverse through the list using the Iterator.
•Print the links text using getText() method.
•Close the browser session with the driver.quit() method.
Find broken Links
“HTTP status codes are the three digit numbers which represent server’s
response to the client’s request.”

Broken links are hyperlinks that point to a page that no


longer exists. They are also known as "dead links" or "link
rots"

Broken links can be caused by:


•Deleting a page
•Moving a page without a redirect
•Changing the URL structure of a website
•A typo in the URL
•Create a WebDriver instance and open URL in the browser "https://demoqa.com/broken".

•HttpURLConnection httpURLConnect=(HttpURLConnection)url.openConnection(): we will


check the HTTP status of each using HttpURLConnection class in Java.
Used to
•httpURLConnect.setConnectTimeout(5000): It is important to wait before creating a check the
connection as the URL may take time to load. We have set the Connection timeout of 5 broken
seconds. URLs

•httpURLConnect.connect() : Now creation of connection happens.

•getResponsecode(): We will fetch the response code and print OK if the URL works fine.
Else will give an error.
Example Table WebElement:

Table /html/body/div[1]/div[2]/div/div[2]/article/div/table/tbody/tr[2]/td[1]

•Part 1 - Location of the table in the webpage


</html/body/div[1]/div[2]/div/div[2]/article/div/
>
•Part 2 - Table body (data) starts from here
<table/tbody/>

•Part 3 - It says table row 2 and table column 1


<tr[2]/td[1]>
Capturing Screenshot
we use an interface called TakesScreenshot, which enables the Selenium WebDriver to capture a
screenshot and store it in different ways. It has a got a method "getScreenshotAs() " which captures
the screenshot and store it in the specified location.
How to take a screenshot of a particular element in Selenium?

/Convert webdriver to TakeScreenshot File screenshotFile =


((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE);

we can use this File object to copy the image at our desired location, as
shown below, using the FileUtils Class.

FileUtils.copyFile(screenshotFile , new File("C:\\temp\\screenshot.png));

1.Take the fullscreen image and then crop the image as per the dimensions of the web element.

2.Using the getScreenshotAs() method on the web element. ( This is available only in selenium version 4.X)

You might also like