Questions/Answers

Question 1 : Write an expression to identify the first link available in the web page.

Answer : driver.findElement(By.tagName(“a”)).click();

Question 2 : Write a code to get the text of the first link available in the web page.

Answer : String str= driver.findElement(By.tagName(“a”)).getText();

Question 3 : Write a code to get the URL of the first link.

Answer : String str= driver.findElement(By.tagName(“a”)).getAttribute(href);

Question 4 : Write a code to get the tool tip of the first link.

Answer :  String str= driver.findElement(By.tagName(“a”)).getAttribute(title);

Question 5 : Write a code to retrieve the current URL of the web page.

Answer :  driver.findElement(By.tagname(“a”)).getTagName();

Question 6 : Write a code to retrieve the tagname of any element that is found.

Answer : driver.findElement(By.id(“un”)).getTagName();

Question 7 : Write a code to move to the previous web page.

Answer : driver.manage().back();

Question 8 : Write a code to move forward to another web page.

Answer : driver.navigate().forward();

Question 9 :  Write a code to refresh a web page.

Answer : driver.navigate().refresh();

Question 10 : Can you refresh a web page without using refresh() method ?

Answer : Actions act=new Actions(driver);

act.sendKeys(Keys.F5).perform();

Add Comment