41 : What kind of software testings are possible
using selenium WebDriver? We can use It for any other purpose except testing
activity?
Answer : Generally we are using selenium WebDriver for functional and
regression testing of software web applications.
42 : Give me any five different xPath syntax to locate bellow given Input element.
<input id="fk-top-search-box"
class="search-bar-text fk-font-13 ac_input" type="text"
autofocus="autofocus" value="" name="q" />
Answer :
Five xPath syntax for above element of software web application page are as
bellow.
//input[@id='fk-top-search-box']
//input[contains(@name,'q')]
//input[starts-with(@class, "search-bar-text")]
//input[@id='fk-top-search-box' or @name='q']
//input[starts-with(@id, 'fk-top-search-box') and
contains(@class,'fk-font-13')]
43 : Can you tell me two drawbacks of xPath locators as compared
to cssSelector locator?
Answer :
Two main disadvantage of xPath locator as compared to cssSelector
locator are as bellow.
- It Is slower than cssSelector
locator.
- xPath which works In one browser
may not work In other browser for same page of software web application
because some browsers (Ex. IE) reads only Lower-cased tag name
and Attribute Name. So If used It In upper case then It will work In
Firefox browser but will not work In IE browser. Every browser reads xPath
In different way. In sort, do not use xPath locators In your test cases of
software web application If you have to perform cross browser testing
using selenium WebDriver software testing tool.
44 : Why xPath locator Is much more popular than all other locator
types In WebDriver?
Answer :
xPath locators are so much popular In selenium webdriver test case development
because
- It Is very easy to learn and
understand for any new user.
- There are many functions to build
xPath In different ways like contains, starts-with etc.. So If one Is not
possible you will have always another option to build xPath of any
element.
- Presently many tools and add-ons
are available to find xpath of any element.
45 : Give me WebDriver's API name using which we can perform drag and
drop operation.
Answer :
That API's name Is Advanced User Interactions API using which
we can perform drag and drop operation on page of software web application.
Same API can help us to perform some other operations too like moveToElement,
doubleClick, clickAndHold, moveToElement, etc..
47 : Do you have faced any technical challenges with Selenium WebDriver software test automation?
Answer :
Yes, I have faced bellow given technical challenges during selenium webdriver
test cases development and running for software web application.
- Sometimes (Not always), Some
elements like text box, buttons etc. are taking more time(more than given
Implicit wait time) to appear on page of software web application or to
get enabled on page. In such situation, If I have used only Implicit wait
then my test case can run fine on first run but It may fail to find
element on second run. So we need provide special treatment for such
elements so that webdriver script wait for element to be present or get
enabled on page of software web application during test execution. We can
use Explicit wait to handle this situation. You can find different
explicit wait example links on THIS PAGE.
- Handling dynamic changing ID to
locate element Is tricky. If element's ID Is changing every time when you
reload the software web application page and you have to use that ID In
XPath to locate element then you have to use functions
like starts-with(@id,'post-body-') or contains(@id,'post-body-')
In XPath. Other alternate solutions to handle this situation are described
in answer of Question 15 of THIS PAGE.
- Clicking on sub menus which are
getting rendered on mouse hover of main menu Is some what tricky. You need
to use webdriver's Actions class to perform mouse hover operation. You can VIEW FULL EXAMPLE on how to
generate mouse hover event on main menu.
- If you have to execute your test
cases In multiple browsers then one test case can run successfully In
Firefox browser but same test case may fail In IE browser due to the
timing related Issues (nosuchelement exception) because test execution In
Firefox browser Is faster than IE browser. You can resolve this Issue by
Increasing Implicit wait time when you run your test In IE browser.
- Above Issue can arise due to the
unsupported XPath In IE browser. In this case, You need to you OTHER ELEMENT
LOCATING METHODS (ID, Name, CSSSelector
etc.)to locate element.
- Handling JQuery elements like
moving pricing slider, date picker, drag and drop etc.. Is tricky. You
should have knowledge of webdriver's Advanced User Interactions API to
perform all these actions. You can find few example links for working with
JQuery Items on THIS PAGE.
- Working with multiple Windows, Frames, and
some tasks like Extracting data from
web table, Extracting data from
dynamic web table, Extracting all Links
from page, Extracting all text
box from page are also tricky
and time consuming during test case preparation.
- There Is not any direct command to
upload or download files from web page using selenium webdriver. For
downloading files usign selenium webdriver, You need to create and set
Firefox browser profile with webdriver test case. You can VIEW PRACTICAL
EXAMPLE.
- Webdriver do not have any built In
object repository facility. You can do It using java .properties file to
create object repository as described In THIS EXAMPLE.
- Webdriver do not have any built In
framework or facility using which we can achieve bellow given tasks
directly : 1. Capturing screenshots, 2. generating test execution log, 3.
reading data from files, 4. Generating test result reports, Manage test
case execution sequence. To achieve all these tasks, We have to use
external services with webdriver like Log4J to generate log, Apache POI
API to read data from excel files, Testng XSLT reports to generate test
result reports. TestNG to manage test case execution, .properties file to
create object repository. All these tasks are very time consuming. ON THIS PAGE, I have
described how to create data driven framework step by step for selenium
webdriver. That framework contains all above functionality.
48 : Can you tell me a syntax to close current
webdriver Instance and to close all opened webdriver Instances?
Answer :
Yes, To close current WebDriver Instance, We can use Close() method as bellow.
Answer :
Yes, To close current WebDriver Instance, We can use Close() method as bellow.
driver.close();
If there are opened multiple webdriver Instances and wants to close all of them then we can use webdriver's quit() method as bellow in software automation test.
driver.quit();
49 : Is It possible to execute javascript directly during software test execution? If Yes then tell me how to generate alert by executing javascript In webdriver script?
Answer :
Yes, we can execute javascript during webdriver software test execution. To generate alert, You can write bellow given code In your script.
JavascriptExecutor javascript = (JavascriptExecutor) driver;
javascript.executeScript("alert('Javascript
Executed.');");
VIEW DIFFERENT EXAMPLES to see usage of WebDriver's JavascriptExecutor.
50 : Give me a syntax to read javascript alert message string, clicking on OK button and clicking on Cancel button.
Answer :
We can read alert message string as bellow.
String alrtmsg = driver.switchTo().alert().getText();
We can click on OK button of alert as bellow.
driver.switchTo().alert().accept();
We can click on Cancel button of alert as bellow.
driver.switchTo().alert().dismiss();