11个基本的硒面试问题 *

Toptal sourced essential questions that the best Selenium developers and engineers can answer. Driven from our community, we encourage experts to submit questions and offer feedback.

现在就雇佣一名顶尖的Selenium开发人员
Toptal标志is an exclusive network of the top freelance software developers, designers, 金融专家, 产品经理, 和世界上的项目经理. Top companies hire Toptal freelancers for their most important projects.

面试问题

1.

你可以使用什么函数/方法来等待页面加载, 或者页面上的某个元素出现?

View answer

要等待页面加载,可以使用显式等待. 显式等待停止,直到满足某些特定条件. Although Thread.Sleep() is a form of explicit wait where the thread stalls for a specific duration of time, it may not be the most reliable way to wait for a page to load.

例如,而不是使用这样的东西:

Thread.睡眠(30000);

… where the thread sleeps for 30 seconds (30,000 milliseconds), the following can be used:

WebDriverWait = new WebDriverWait(webDriver,30);
wait.直到(ExpectedConditions.visibilityOf (h1));

… where Selenium waits until the given element is visible on the page, 或在等待30秒后抛出TimeoutException.

2.

什么是页面对象模型和页面工厂在硒?

View answer

Page Object Model in Selenium is a design pattern where web pages are represented using classes. Variables in the class can then be used to hold references to elements on the web page, 方法可以用来实现行为. This allows an elegant way of implementing test routines that are both readable and easier to maintain and extend in the future.

clickLoginButton ();
setCredentials (user_name user_password);
submitLoginForm ();

Page Factory is used to initialize every WebElement variable with a reference to a corresponding element on the actual web page using configured “locators”. Annotations, 例如@FindBy, 可以用来定义查找元素的策略吗, 连同识别他们的必要资料:

@FindBy(如何=.的名字,使用= "用户名")
私有WebElement user_name;

可以找到更多关于页面对象模型和页面工厂的信息 here.

3.

如何在页面上处理Selenium中的框架元素?

View answer

In order to manipulate frame and its content you must switch to it first. This is similar to how you have to switch to a different page before you can interact with it:

driver.switchTo().框架(指数);

… where index 是坐标系的从零开始的索引吗. Switching the frame directs all further interactions through the driver towards the selected frame. The frame method also works with name, element ID and reference to already located elements.

要切换回默认帧,请使用 defaultContent 方法可采用:

driver.switchTo().defaultContent ();

申请加入Toptal的发展网络

并享受可靠、稳定、远程 自由Selenium开发人员职位

申请成为自由职业者
4.

What are some differences between CSS selector and XPath based locators?

View answer
  • CSS选择器通常比XPath更容易阅读. Most front-end developers are more likely to be familiar with CSS selectors already.

  • Support for CSS selectors is quite consistent across various modern web browsers, 而他们的XPath引擎却不是这样.

  • CSS选择器比XPath工作得快.

出于各种原因, 比如上面列出的那些, Selenium “best practices” advise the use of CSS selectors over XPath.

5.

How do you write a locator to identify paragraph elements that are the immediate child of a div element, 或者div元素的子元素?

View answer

直接子:

An immediate child in XPath is defined indicated using “/”, while on CSS, it is indicated using “>”. 例如,使用XPath:

//div/p

使用CSS:

div > p

后代:

To find paragraph elements that are descendent to any div element (i.e. the paragraph element appears in the subtree rooted at the div element), 我们可以在XPath中使用“//”, 只是一个空白的CSS:

//div//p
div p
6.

简单解释一下下面这段Java代码的作用:

WebElement样本= driver.findElement(通过.xpath(" / / *[包含(文本()、“数据”)]"));
View answer

它定义了一个变量 sample 类型为WebElement, and uses an XPath search to initialize it with a reference to an element that contains the text value “data”.

7.

如何将文本输入发送到焦点元素?

View answer

This can be done by simulating key presses on the focused element. 一种方法是在web驱动对象上执行“actions”:

新的行动(webDriver).sendKeys(“文本”).perform();

An alternative way is to switch to the active element first, and send keys to it directly:

webDriver.switchTo().activeElement ().sendKeys(“文本”);
8.

为什么我们要使用无头驱动程序? How can you visually investigate test failure when using headless drivers?

View answer

无头的司机 are typically used in continuous integration (CI) setups. 无头的司机, 比如PhantomJS, 提供所有标准的web浏览器功能, 但是在命令行中运行. These drivers are based on command-line tools and don’t produce screen output, 使它们成为完全自动化设置的理想选择.

能够直观地调查测试失败, the developer needs to implement mechanisms to capture screenshots, 否则依赖于命令行输出.

9.

绝对xpath与相对xpath有什么不同? Why are relative XPaths typically preferred over absolute XPaths in automated tests?

View answer

Absolute XPaths, in terms of web pages, start with the root element:

html /头/身体/表/身体/ tr / th

另一方面,相对xpath通常以" // "开头:

/ /表/身体/ tr / th 

Even though both these XPaths probably refer to the same element on a certain web page, the former one is more likely to break with any change made to the page. For example, moving the table to inside of a div element will stop the absolute XPath from being able to locate the th element. On the other hand, the relative XPath will still continue to work.

10.

什么是Selenium中的混合框架?

View answer

A hybrid framework is a combination of keyword- and data-driven frameworks.

11.

什么是StaleElementException ?

View answer

It is the exception thrown when the invoked element is no longer attached to the DOM for any reason.

There is more to interviewing than tricky technical questions, 所以这些只是作为一个指南. Not every “A” candidate worth hiring will be able to answer them all, 回答所有问题也不能保证成为A级考生. 一天结束的时候, 招聘仍然是一门艺术,一门科学,需要大量的工作.

Why Toptal

厌倦了面试候选人? 不知道该问什么才能让你得到一份好工作?

让Toptal为你找到最合适的人.

现在就雇佣一名顶尖的Selenium开发人员

我们的专属网络硒开发人员

希望找到一份作为Selenium开发人员的工作?

让Toptal为你找到合适的工作.

作为Selenium开发人员应用

工作机会从我们的网络

提出面试问题

Submitted questions and answers are subject to review and editing, 并可能会或可能不会选择张贴, 由Toptal全权决定, LLC.

*所有字段均为必填项

寻找Selenium开发人员?

寻找 硒的开发人员? 查看Toptal的Selenium开发人员.

Papuna Gagnidze

自由Selenium开发人员
GeorgiaToptal成员 Since 2019年11月21日

Papuna is a highly skilled QA automation and DevOps engineer with experience in Linux system administration and network engineering. He has leadership experience in QA teams and skills for delivering high-quality end-to-end tests. Papuna has designed architectures and implemented scalable systems using microservices and serverless architecture.

Show More

Deniz Hamamcioglu

自由Selenium开发人员
TurkeyToptal成员 Since 2018年12月12日

Deniz has over nine years of experience in software test automation, framework, 以及测试架构设计. He led and mentored teams and created guidelines about testing. Deniz是硒方面的专家, Cypress, Playwright, WebdriverIO, Protractor, and many other test automation technologies and programming languages. He communicates exceptionally well and has a keen eye for details. 丹尼斯过去几年一直在远程办公, 提供跨大洲的专家指导.

Show More

Jovana苦

自由Selenium开发人员
SerbiaToptal成员 Since 2018年3月22日

在过去的七年里, Jovana has worked as a QA engineer collaborating with various QA teams and on complex functional testing (manual and automation) on multiple types of applications. She's passionate about bug hunts and is known as a hard-working team player who loves to learn. Jovana thrives under pressure and this can be seen in her history of successfully dealing with deadlines and product deliveries.

Show More

Toptal连接 Top 3% 世界各地的自由职业人才.

加入Toptal社区.

Learn more