面试题_Selenium

来源:互联网 发布:352净化器怎么样 知乎 编辑:程序博客网 时间:2024/06/05 04:10

1.What is selenium composed of?

  • Selenium IDE: is a tool for recording and playing back
  • WebDriver: It provide the APIs for variety of languages like java,.NET,php.
  • Grid: With the help of Grid you can distribute test on multiple machines.

2.How many ways does Selenium provide to find a element?

  • ID
  • Name
  • Tag
  • Xpath
  • CSS
  • Attribute
  • Linktext
  • PartialLinkText

3.Explain the single and double slash in xpath.

  • single slash enables to create absolute path expression which means need to start selection from the document node
  • double slash enables to create relative path expression which means it can match elements anywhere from document

4.Use xpath to identify the “input” Web element in bold in below html code

<div id="div1">    <input name="input1" class="div1"/>    <input name="input2" class="div1"/></div><div id="div2">    <input name="input1" class="div2"/>    <input name="input2" class="div2"/> <!--查找该元素--></div>
  • //div[@id=’div2’]/input[@name=’input2’]
  • //input[@id=’div2’ and class=’div2’]

5.What is difference between verify and assert commands?

  • Assert: Assert allows to check whether an element is on the page or not. The test will terminate at the point if the assert fails.
  • Verify: Verify command will check whether an element is on a page too, but the test will continue even if it fails

6.What si the difference between setSpeed() and sleep() method?

  • Both will delay the speed of execution
  • Thread.sleep(): It will stop the current java thread for the specified period of time
  • setSpeed(): For specific amount of time it will stop the execution of every selenium command

7.How you can use “submit” a form using Selenium?

  • You can use submit() method for the element in form, like element.submit();
  • Or you can just use click() method for the submit button, like Btn.click();

8.What are the features of TestNG and list some of the functionalities.

TestNG is a testing framework for Unit test and Integration test
- Support for annotations
- Support for data driven testing
- Flexible test configurations


9.Which attribute you should consider throughout the script in frame for ” if no frame id as well as no frame name”?

You can use driver.findEelements(By.xpath(“//iframe”)); or By.tag(“iframe”)
This will return a list of iframe elements.
Create a loop to find which one you need and break the loop


10.How can you perform double click for an element?

Actions action = new Actions(driver);action.doubleClick(element).perform();

11.How to choose a option in a selection?

Select select = new Select(driver);select.selectByIndex(index);select.selectByValue(value);select.selectByVisableText(text);

12.Explain Page Object pattern in Selenium.

A page object pattern is object-orientation class that servers as an interface to a page.


13.Can Selenium find element with (display=none)? If yes, please explain how to do it.

JavascriptExecutor js = (JavascriptExecutor) mDriver;js.executeScript("argument[0].style.display='block'");

14.How many ways for Selenium to wait for element in page?

Implicit wait & explicit wait


15.How to move between windows and frames?

driver.switchTo().window();drivr.switchTo().frame();

16.Write a sql statement to draw second highest salary in Employee table.

Table structure is : Employee ID, Name, Salary

select max(salary)from Employeewhere salary NOT IN (                    select max(salary)                     from Employee                    )

17.Given a table SALARIES such as the one below , that has m= male and f = female values. Swap all f and m values with a single update.

UPDATE SALARIES SET gender = (                        case gender when 'm' then 'f'                        else 'm'                        end                        )
UPDATE SALARIES SET gender = decode(gender                                    'm','f',                                    'm')

原创粉丝点击