By: Dharm Dev
By: Dharm Dev
By: Dharm Dev
1. What is Selenium?
Syntex:
driver.findElement(By.xpath(".//*[@id='nam
efield']")).sendKeys("Dharm");
24. How can we get text of a web element
in selenium ?
Syntex:
String address= driver.findElement(By.xpath
(".//*[@id=‘address']")). gettext();
25. How can we submit a form in
selenium ?
selectByVisibleText
selectByIndex
Syntex:
Select dropdown=new Select(driver.findElement
(By.xpath(".//*[@id=‘submit']")).selectByIndex(1);
28. What are the different types of
navigation commands?
Different navigation commands are-
navigate().back() – takes back the user to
the previous webpage in the web browser’s
history.
Syntex: driver.navigate().back();
navigate().forward() –navigate to next web
page with reference to the browser’s history.
Syntex: driver.navigate().forward();
navigate().refresh() – This command
refresh the current web page there by
reloading all the web elements.
Syntex: driver.navigate().refresh();
navigate().to() – This command launch a
new web browser window and navigate to the
specified URL.
Syntex:
driver.navigate().to(“https://google.com”);
29. When do we use findElement() and
findElements() ?
findElement(): is used to find the first element in the
current web page matching to the specified locator value
Syntax: WebElement element = driver.findElements
(By.xpath(“//div[@id=’list’]//ul//li”));
findElements(): is used to find all the elements in the
current web page matching to the specified locator
value. all the matching elements would be fetched and
stored in the list of WebElements.
Syntax: List <WebElement> elementList =
driver.findElements(By.xpath(“//div[@id=list’]//ul//li”));
30. Can Selenium handle window based Popup?
windows pop up cannot be handled using
Selenium, because Selenium is an automation
testing tool which supports only web
application testing.
There are several third party tools available
for handling window based pop ups along with
the selenium like AutoIT, Robot class etc.
31. How Can Selenium handle web based Popup?
WebDriver offers a very efficient way to handle these pop
ups using Alert interface. There are the four methods:
void dismiss() –This method clicks on the “Cancel”
button as soon as the pop up window appears.
void accept() – method clicks on the “Ok” button as
soon as the pop up window appears.
String getText() – The getText() method returns the
text displayed on the alert box.
void sendKeys(String stringToSend) –method enters
the specified string pattern into the alert box.
Syntax: driver.switchTo().alert().accept();
32. How can we find if an element is
displayed on screen?
WebDriver facilitates following methods
to check the visibility of the web elements.
These web elements can be buttons, drop
boxes, checkboxes, radio buttons, labels etc.
isDisplayed()
isSelected()
isEnabled()
Syntax: boolean button = driver.findElement
(By.id(“next”)).isDisplayed();
33. How to click on a hyper link using
linkText?
We can use these element locators for
locating hyperlink text.
By linkText(“String”);
By partialLinkText(“String”);
“partialLinkText is accessing links using a
portion of their link text”.
Syntex:
driver.findElement(By.linkText(“google")).click();
34. How to mouse hover on a web
element using WebDriver?
we used Action Interface to mouse hover
on a web element (eg. drop down) which
then opens a list of options.
Syntex:
Actions actions=new Actions(driver);
actions.moveToElement(driver.findElement(By.id(“se
x"))).perform();
driver.findElement(By.id(“male")).click();
35. How to retrieve css properties of an
element?
The values of the css properties can be
retrieved using a get() method:
Syntax:
driver.findElement(By.id(“id”)).getCssValu
e(“font-size”);
36. How to assert title of the web page?
Syntex:
assertTrue(“The title of the window is
incorrect.”,driver.getTitle().equals(“Title of
the page”));
37. How to select a value in dropdown?