Free Selenium with Java Online Test -2

Instructions

  1. Read each question carefully before selecting an answer.
  2. Each question has only one correct answer.
  3. Click on the radio button next to your chosen option.
  4. You may change your selection before submitting.
  5. Once you’ve answered all the questions, click the “Submit Quiz” button.
  6. Your score, correct answers, and any unanswered questions will be displayed below the quiz.
  7. Correct answers will be marked with and wrong answers with .

Q1. What is the output of the following Selenium WebDriver code in Java?

HTML Code:

<ul id='fruitList'>
  <li>Banana</li>
  <li>Apple</li>
  <li>Orange</li>
  <li>Mango</li>
</ul>
  

Selenium Script:

System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("test_page_url_html_code_exists"); // Load the page
String val = driver.findElement(By.xpath("//ul[@id='fruitList']//li[1]")).getText();
System.out.println(val);
  

Select one:




Q2. What is the output of the following Java code?

class Main {
  public static void main(String[] args) {
    System.out.print(countSum());
  }
  public static int countSum(){
    int sum;
    for(int i=0; i<5; i++){
      sum = sum + 5;
    }
    return sum;
  }
}
  

Select one:




Q3. What is the output of the following Java code?

class Main {
  public static void main(String[] args) {
    System.out.print(countSum());
  }
  public static int countSum(){
    int sum = 0;
    for(int i=0; i<10; i++){
      sum = sum + i;
    }
    return sum;
  }
}
  

Select one:




Q4. What is the output of the following Selenium WebDriver code in Java?

HTML Code:

  <input type="text" id="inputText" value="Enter first name" />

Selenium Script:

System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("test_page_url_html_code_exists");
String val = driver.findElement(By.id("inputText")).getAttribute("value");
System.out.println(val);
  

Select one:




Q5. What is the output of the following Selenium WebDriver code in Java?

HTML Code:

  <input type="text" id="inputText" value="" />

Selenium Script:

System.setProperty("webdriver.chrome.driver", "path/to/chromedriver");
WebDriver driver = new ChromeDriver();
driver.get("test_page_url_html_code_exists");
driver.findElement(By.id("inputText")).sendKeys("testing talks latest");
String val = driver.findElement(By.id("inputText")).getAttribute("value");
System.out.println(val);
  

Select one:




Q6. What is the correct Selenium script to accept an alert popup in Java?

Select one:




Q7. Which method is used in Selenium WebDriver with Java to check whether an element is displayed?




Q8. Which of the following Selenium scripts clears text from an input box?




Q9. What is the output of the following Java code?

List<Integer> list = new ArrayList<>();
list.add(1);
list.add(2);
list.add(5);
list.add(7);
System.out.print(list.get(2));
  



Q10. What is the output of the following Java code?

HashMap<Integer, Integer> map = new HashMap<>();
map.put(1, 5);
map.put(2, 9);
map.put(3, 10);
map.put(4, 11);
System.out.print(map.get(4));
  





0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Subscribe to our YouTube Channel: Testing Talks Latest
Testingtalkslatest.com - A project by CreativeHub IT Solutions.
Contact Us At: support@testingtalkslatest.com
Our Partner websites - Classified Hub , CodesToolbox
Scroll to Top
0
Would love your thoughts, please comment.x
()
x