selenium common interview questions and answers (Java version)

1. how to determine whether there is an element?

Judge element exists and whether there are different, this means that if there is to determine whether the elements simply do not exist, will throw NoSuchElementException

So you can use try catch, if it returns false catch to NoSuchElementException

 

2. How to determine whether there is an element?

Determining whether there is an element, there are two cases, one is the element they not, does not occur naturally; another is such elements, but the state is hidden

By first determining whether there is, if there is no return false; if there is again determined whether displayed

3. How to choose the drop-down menu elements

 Drop-down menu two types, one is the direct use of the select tag, this may be used as selenium API 

Reference: http: //www.cnblogs.com/tobecrazy/p/4570494.html 

Selector = driver.findElement WebElement (By.id ( "Selector")); 
the Select = select the Select new new (Selector); 
selecting the option select the following three methods 

selectByIndex (int index) by index 
by matching the selectByVisibleText (String text) the visible characters 
selectByValue (String value) by matching the tag's value

The second drop-down menu is not achieved through select, can be operated by JS

Like this: http: //css3menu.com/ (DevTools on how to use your own Baidu, do not explain)

Then such a how to select the menu?

Show you can call it a day, move the mouse to the first step in how to use, menu appears at this time; the second step, click on Technical Question

To achieve the first step, the use of selenium Action clickAndHold, can then be operated findByElement

    WebElement menu = driver.findElement(By.xpath("//span[.='How to Use']"));
        
        Actions action = new Actions(driver);
        action.clickAndHold(menu).build().perform();
        WebElement technicalQuestion = driver.findElement(By.xpath(
                "//ul[@id='css3menu_top']/li[position()=3]/div[@class='submenu']/div[@class='column']//a[contains(text(),'Technical')]"));
        technicalQuestion.click();

 

4. selenium locate several ways, the most common kind of you, and why?

There are eight selenium positioning mode, three ByName and name-related, ByClassName, ByTagName

                                   2 and relative to the link ByLinkText, ByPartialLinkText

                                   And id related to a ById

                                  The remaining two Almighty ByXpath and ByCssSelector

The most common thing I ByXpath (or CssSelector) because in many cases, property html tags are not standardized, not by a single attribute positioning, you can only use this time to re-xpath can achieve a unique positioning element

In fact the fastest positioning should belong ById, because id is unique, but most developers do not set the id

5. Where network interview questions Java implementation

一、 UI自动化测试
1、 Qunar机票搜索场景
1) 访问Qunar机票首页http://flight.qunar.com,选择“单程”,输入出发、到达城市,选择today+7日后的日期,点“搜索”,跳转到机票单程搜索列表页。
2) 在列表页停留1分钟,至到页面上出现“搜索结束”。
3) 如果出现航班列表,对于出现“每段航班均需缴纳税费”的行随机点选“订票”按钮,在展开的列表中会出现“第一程”、 “第二程”;对于没有出现“每段航班均需缴纳税费”的行随机点选“订票”按钮,在展开的列表底部中会出现“报价范围”
4) 如果不出现航班列表,则页面会出现“该航线当前无可售航班”

Refer to my Blog,  http://www.cnblogs.com/tobecrazy/p/4752684.html

6. How to locate elements on the page dynamically loaded?

    Dynamic event trigger event, then findElemnt

    If the menu is dynamic, you need a find a

7. How to locate the element attributes dynamic?

  Dynamic changes of properties means that the property value element is not fixed, it can only be positioned relative position

    Xpath such as by the shaft, parent / following-sibling / precent-sibling, etc.

    Alternatively, you can try to traverse findbyelements

 

8. how to improve the efficiency of selenium script automation?

  •   Optimization of test cases, as much as possible without using SLEEP, ImplicitlyWait reduce
    , the use of selenium in the wait / FluentWait, so that waiting time can be optimized
  •  Use selenium grid, achieve concurrent execution by testng
  •  For dynamic controls to achieve some unstable operation by JS
  •  Overloaded testng the listener realize retry mechanism, improve the success rate of test cases
  •  IE reduce the driver, IE efficiency is too low! ! !

9. webdriver What is the principle?

Reference: http: //www.cnblogs.com/tobecrazy/p/5034408.html

 

10. selenium in how to ensure the success rate of the operation elements? That is how to ensure that I click on certain elements are clickable?

Reference: http://www.cnblogs.com/tobecrazy/p/4817946.html

  • WaitforEmelentPresent achieved by encapsulating the find method, so that prior to the operation to ensure that the element is found elements, thereby improving the success rate
  • Before operating elements, such as click, if the element is not display (non-hidden), you need to scroll to the element, and then click operation

  Why use the scroll? Because if the page is not completely displayed, element if it is to appear in the drop-down after it, can only scroll to the first element to be click, otherwise it is not click operation

1
2
3
JavascriptExecutor js=(JavascriptExecutor)driver;
         // roll down and keep the element to the center of browser
         js.executeScript( "arguments[0].scrollIntoViewIfNeeded(true);" , download);

 

11. What PO mode, what is the page factory?

    There are many online answers, not comprehensive

    PO mode is the abbreviation for page object model, by definition, is a design pattern, to achieve real page and Web page scripts Map up, one-up. This will test framework easier to maintain. For example, a landing page, after using PO mode, creates a LoginPage of class, webElenent This class defines the user name input box, enter the password box, landing button

For the corresponding Element implement the corresponding method, the input box is used to enter, you need to create a method for a user name and password, so it is consistent and real page, so this design philosophy is PO mode. The PageFactory under the PO mode, is used to initialize each PO mode to achieve the Page Class, initialize the object library.

 

To be continued, if you encounter selenium face questions can not answer, please leave a message! 

References:

selenium official API: http://seleniumhq.github.io/selenium/docs/api/java/index.html

Where mesh questions ethanol: HTTP: //www.cnblogs.com/nbkhic/p/3657035.html

the Java questions face big collection

Guess you like

Origin www.cnblogs.com/pythongood/p/11204730.html