使用多个条件在Selenium中查找WebElement [英] Using multiple criteria to find a WebElement in Selenium

查看:745
本文介绍了使用多个条件在Selenium中查找WebElement的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Selenium来测试网站,如果我发现并按多个标准进行元素搜索是否可以正常工作?例如:

I am using Selenium to test a website, does this work if I find and element by more than one criteria? for example :

 driverChrome.findElements(By.tagName("input").id("id_Start"));

driverChrome.findElements(By.tagName("input").id("id_Start").className("blabla"));

推荐答案

不,不是.您不能像这样串联/添加选择器.反正这是无效的.但是,您可以这样编写选择器,使其涵盖所有场景并将其与findElements()

No it does not. You cannot concatenate/add selectors like that. This is not valid anyway. However, you can write the selectors such a way that will cover all the scenarios and use that with findElements()

By byXpath = By.xpath("//input[(@id='id_Start') and (@class = 'blabla')]")
List<WebElement> elements = driver.findElements(byXpath);

这应该返回具有input标签的元素列表,这些标签的类名称为blabla并且具有id id_Start

This should return you a list of elements with input tags having class name blabla and having id id_Start

这篇关于使用多个条件在Selenium中查找WebElement的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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