• Slider Banner

    Prepare for

    Technical Interview

    Over .1 Million+ Interview Questions for different profiles

    Read More
  • Slider Banner

    Join the

    Programming World

    Learn about top programming languages, tools and frameworks.

    Read More
  • Slider Banner

    Prepare with

    Certification MCQ

    Practice for certification from 1000+ multiple choice questions.

    Read More

What will be the output of below Java code?

Sample Code: 

public  class  A  
{
    public void m1(int ... i)
    {
        System.out.println("Parent class");
    }
}

public class B extends A
{
    public void m1(int i)
    {
        System.out.println("child class");
	}
}

class C
{
    public static void main(String[] args)
    {
        A a = new A();
        a.m1(10);

        B b=new B();
        b.m1(10);

        A a1=new B();
        a1.m1(10);
    }
}

Output:

Parent class

child class

Parent class

How do you click on a menu item in a drop down menu in Selenium?

If that menu has been created by using select tag then we can use the methods selectByValue() or selectByIndex() or selectByVisibleText(). These are the methods of the Select class.

If the menu has not been created by using the select tag then we can simply find the xpath of that element and click on that to select.

How do perform drag and drop using Selenium WebDriver?

Use Action Class:

Actions act = new Actions(driver);
WebElement source = driver.findElement(By.xpath("")); //source element which you want to drag
WebElement target = driver.findElement(By.xpath("")); //target where you want to drop
act.dragAndDrop(source, target).perform();

How do you launch IE/Firefox/Chrome browser using Selenium?

Check below code:

WebDriver driver;

if(browser.equals("Chrome"))
{	
    System.setProperty("webdriver.chrome.driver", Constants.CHROME_EXE);
    driver = new ChromeDriver();
}
else if(browser.equals("Firefox")) 
{
    System.setProperty("webdriver.gecko.driver", Constants.FIREFOX_EXE);
    driver = new FirefoxDriver();
}
else if(browser.equals("IE"))
{
    System.setProperty("webdriver.ie.driver","Constants.IE_EXE");
    driver = new InternetExplorerDriver();
}

How do you handle alert in Selenium?

To handle alert pop-ups, we need to 1st switch control to alert then click on ok or cancel then move control back to main page.

String mainPage = driver.getWindowHandle();

Alert alt = driver.switchTo().alert(); // to move control to alert popup
alt.accept(); // to click on ok.
alt.dismiss(); // to click on cancel.

//Then move the control back to main web page
driver.switchTo().window(mainPage);
Subscribe to