0% found this document useful (0 votes)
19 views

Automation Assignments

The document contains three problem statements and their solutions. The first problem is to print the suggestive dropdown of a Google search. The second is to find duplicate characters in a string. The third is to find the largest and smallest words in a given string.

Uploaded by

shrivaibhs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

Automation Assignments

The document contains three problem statements and their solutions. The first problem is to print the suggestive dropdown of a Google search. The second is to find duplicate characters in a string. The third is to find the largest and smallest words in a given string.

Uploaded by

shrivaibhs
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Date:13/04/2024.

Name Vaibhav Srivastava

Assignment submitted to Akshay.

Problem Statement 1: Print the suggestive dropdown of google search.

//*[@id="APjFqb"]

/html/body/div[1]/div[3]/form/div[1]/div[1]/div[2]/div[4]

/html/body/div[1]/div[3]/form/div[1]/div[1]/div[2]/div[4]

Sol:

public static void main(String[] args) {


// TODO Auto-generated method stub
WebDriver wd;
WebDriverManager.chromedriver().setup();
wd=new ChromeDriver();
wd.get("https://www.google.com/");
WebElement
searchbox=wd.findElement(By.name("q"));
searchbox.sendKeys("vaibhav");
try {
Thread.sleep(3000);
}catch (InterruptedException e) {
e.printStackTrace();
}

List<WebElement>list=wd.findElements(By.xpath("//ul[@rol
e='listbox']//li[@role='presentation']"));
for(WebElement ele:list)
{
System.out.println(ele.getText());
}
}
o/p”

vaibhav pandya
Vaibhav Rekhi
Businessman ? Dia Mirza's husband
Vaibhav Mangle
Actor
Vaibhav Chinese centre
Chinese restaurant � 223, Eastern Express Hwy, Namdeo
Vadi, Panch Pakhdi, Thane West, Thane, Maharashtra
vaibhav hotel mulund west
Hotel Vaibhav Pure Veg � NS Rd, opp. Police Station,
Jagjivan Ram Nagar, Mulund West, Mumbai, Maharashtra
Vaibhav Reddy
Indian actor
vaibhav tatwawadi movies
vaibhav pandya parents
vaibhav travels
Vaibhavi Upadhyay
Actress
Problem Statement 2: Write a program to find duplicate character.

input: "Chamberlain Group Pune Innovation Center"

output: "Caerin out"

public static void main(String[] args) {


// TODO Auto-generated method stub
/*
* Problem Statement 2: Write a program to find duplicate
character.
input: "Chamberlain Group Pune Innovation Center"
output: "Caerin out"

* */
String str="Chamberlain Group Pune Innovation
Center";
char [] charArr=str.toCharArray();
Map<Character,Integer>charMap=new
HashMap<>();
for(char c:charArr)
{
if(charMap.containsKey(c))
{
charMap.put(c, charMap.get(c)+1);
}else
{
charMap.put(c, 1);
}
}
// to print value
//Set<Map.EntrySet<Character,Integer>>
entrySet=charMap.entrySet();

for(Map.Entry<Character,Integer>entry:charMap.entrySet())
{
if(entry.getValue()>1)
{
System.out.println(entry.getKey());
}
}
}

}
o/p:

aCeinortu

Problem Statement 3: Write a program to find the largest and smallest word in the string.

input: "Chamberlain Group Pune Innovation Center"

output:

largest - Chamberlain
smallest - Pune

sol:

package testPackage;

public class ProblemStmt03 {

public static void main(String[] args) {


//Problem Statement 3: Write a program to find the largest and
smallest word in the string.
// input: "Chamberlain Group Pune Innovation
Center"
// output:
// largest - Chamberlain
// smallest - Pune
String text= "Chamberlain Group Pune Innovation
Center";
//split into word
String[] words=text.split("\\s+");
//init string var to null
String largestWord=null;
String smallestWord=null;
//iterating to compare each word length
for(String word:words)
{
if(smallestWord==null ||
word.length()<smallestWord.length())
{
smallestWord=word;
}
if(largestWord==null ||
word.length()>largestWord.length())
{
largestWord=word;
}
}
System.out.println("Smallest word in given string is
:" +smallestWord);
System.out.println("Largest word in given string
is :" +largestWord);

o/p
Smallest word in given string is :Pune
Largest word in given string is :Chamberlain

You might also like