何时以及如何使用Selenium Webdriver通过Tagname定位元素?请举例说明 [英] When and how I can locate element by Tagname using selenium webdriver? Please explain with an example

查看:324
本文介绍了何时以及如何使用Selenium Webdriver通过Tagname定位元素?请举例说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用硒进行测试时,我已经使用了大多数元素定位器,但是使用频率很低的"TagName"定位器却很少.请举个例子.

I have used most of the element locator while Testing with selenium but very low frequently used 'TagName' locator. Please give and example.

推荐答案

现在假设,软件Web元素没有任何ID或类名,那么如何在Selenium WebDriver中定位该元素?答案是硒WebDriver元素定位器有很多替代方法,其中之一是按标记名定位元素.

Now supposing, software web element do not have any ID or Class Name then how to locate that element in selenium WebDriver ? Answer is there are many alternatives of selenium WebDriver element locators and one of them is Locating Element By Tag Name.

按标签名称查找元素并不是很流行,因为在大多数情况下,我们将有元素查找器的其他替代方法.但是,是的,如果没有其他选择,则可以使用元素的DOM标签名称在webdriver中定位该元素.

Locating Element By Tag Name is not too much popular because in most of cases, we will have other alternatives of element locators. But yes if there is not any alternative then you can use element's DOM Tag Name to locate that element in webdriver.

您可以在此处选择标记名作为定位器,例如:

Here you can select the tagname as a locator like:

//Locating element by tagName and store its text in variable dropdown.
 String dropdown = driver.findElement(By.tagName("select")).getText();

这篇关于何时以及如何使用Selenium Webdriver通过Tagname定位元素?请举例说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆