面试题_Selenium

本文涵盖Selenium自动化测试的基础概念和技术细节,包括Selenium的组成、定位元素的方法、XPath详解、常见操作如双击及表单提交等,并探讨了Page Object模式的应用,以及如何处理不可见元素。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 Employee
where 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'
)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值