Selenium Question 4

Q1. How to simulate key board button through selenium ?

In place of .click(“username”) write .sendkey(“username”)
.sendkey (Keys.Enter); // It will press enter.

Q2. How to attach a file or upload a file?

 Selenium do not support mouse movement
Select the text box by its Xpath and type the picture path by send key
Example:- driver.findelement(by.xpath(“///”)).sendkey(“picture path”);

Q3. Selecting the Date ?

Just find its Xpath and click on it.

Q4. How to handle a dynamic table ?

List <WebElement> rows = table.findelements(by.tagname(“tr”);
System.out.println(“total rows ->”+rows.size());
As every row xpath is under tag name tr

Q5. What is webdriver.timeouts ?

Driver.manage().timeout().implicitewait(5, timeunit.seconds)
It will wait for 5 seconds after that it will throw an error if the value not found.
It load the complete page before throwing any error, If the above page do not load in 10 second it will give an error. It is similar to synchronization time out in QTP.
It give object of webdriver time out.

Q6. How to simulate back and front button on selenium ?

If we want to click on back button.
In place of get click on navigate, as get do not support back and forward buttons.

Q7. How to scroll your side bars ?

//You have to use event driven driver
Eventdriver driver = new eventFiringDriver
Scrolling is done through java script.

Q8. How to extract values?

Example :- set of itons(140)
And we need 140
String text = set of itons(140)
String temp [] = Linktext.split(“\\”(“);
Print temp[1]
It will show 140
So remove another bracket
Temp = temp[1].split(“\\)”);
Print temp[0]
So now 140 will be printed.

Q9. Data Driven frame work ?

In which all the things are controlled by a excel file. where we put all the properties in it and java code will read from it.
Create a new Xpath or or name file.
It will have all the xpath in it, we do it if we hard code it in selenium and developer change it then we have to change every where here we have to change only one place.
Create a package
Create a class
// inilitize the property file
Public static properties CONFIG = null;
Public static properties OR = null;
Public static webdriver dx = null;
Public static EventFiringwebdriver  driver= null;
Public void initialize()
//here we have created a initialize mehod which will initialize config and OR
Config = new properties ();
Fileinputsteram fn = new fileinputstream(system.getproperty(“user.dir”)+”//src//config//;
// Now initialize OR. Properties
OR = new properties ();
Fileinputsteram fn = new fileinputstream(system.getproperty(“user.dir”)+”//src//config//;
//Now initialize the driver
Then initialize the driver with the browser.
// you need to implement event firing webdriver for mouse events etc
EventFiringWebDriver driver = new EventFiringWebDriver(driver)
// Now give webdriver implicit wait.
// it will give path of current project
.. now use assertion of junit
// now create a class extending above base class
Eg :- in new test class
Public class login extend testbase{
//so all the properties and driver object is from extended class
// Now create the separate function for all the common working like login. Which will extend the calling class.
“//” used if there is some special character.
And what ever we are getting put in an array.

Q10. What is difference between assertion and error collector? 

Assertion fails the script stop the execution
Error collector we can report all the errors

No comments:

Post a Comment