Seleium ms
Published: 2022-10-12 17:45:48

                      Practical - 1
Q: Launch any Web browser, Open Website
(https://nuv.ac.in), Print Title, and URL of this Website.

Code:

package practical1;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.chrome.ChromeDriver;
public class Main {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"/Users/surajsatheesh/Developer/Selenium
drivers//chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://nuv.ac.in");
System.out.println(driver.getTitle());
System.out.println(driver.getCurrentUrl());
}
}



                    Practical – 2

Q: Launch any web browser , use Locators – ID, Name,
className , use Click() method on any button and print
size .

Code:

package Practical2;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
public class main {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver",
"/Users/surajsatheesh/Developer/Selenium
drivers/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("https://www.saucedemo.com/");
driver.findElement(By.id("username")).
sendKeys("standard_user");
driver.findElement(By.name("password")).sendKeys("secret_sauce
");
driver.findElement(By.className("submitbutton")).
click();
driver.findElement(By.linkText("Sauce Labs
Backpack")).click();
driver.findElement(By.partialLinkText("Hello")).click();
List < WebElement> webElementList =
driver.findElements(By.partialLinkText("Sauce"));
System.out.println("Element Sizes : " +
webElementList.size());
}
}


                     Practical – 3
Q: Launch any Web browser, Open Website
(https://www.amazon.in/), Print Title, URL of this
Website , size, use tagname by Anchor tag and print list
of hyperlinks of that page.

Code:


package Hyperlink;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import java.util.List;
public class Main {
public static void main(String[] args) {
System.setProperty("webdriver.chrome.driver","/Users/
surajsatheesh/Developer/Selenium
drivers//chromedriver");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.amazon.in/");
List<WebElement> hyperlinks =
driver.findElements(By.tagName("a"));
System.out.println("Total Links" +
hyperlinks.size());
for(WebElement Links: hyperlinks){
System.out.println(Links.getText());
}
}
}

                    Practical – 4

Q: Launch any Web browser, Open Website
(https://www.opencart.com/index.php?route=account/re
gister), Print Title, URL of this Website , print size and
Print dropdown list of that Country and use isMultiple()
Method.

Code:
package dropdown;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;
public class Main {
public static void main (String[] args){
System.setProperty("webdriver.chrome.driver", "");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://www.opencart.com/index.php?route=account/r
egister");
WebElement element = driver.findElement(By.id("inputcountry"));
Select dropdown = new Select(element);
dropdown.selectByVisibleText("India");
if(dropdown.isMultiple()){
System.out.println("Dropdown is multiple");
}
else
{
System.out.println("Dropdown is not multiple");
}
}
}