How to use multiple locators to find an element in selenium webdriver

五迷三道 提交于 2019-12-05 18:21:20

Xpath allows you to use and and or to evalute multiple attributes. so you can form an xpath using this

//input[@id='id' and @value='value1' or @value='value2']

For example on google home page, there are two buttons, Google Search and I'm Feeling Lucky. Both has same type submit to find these buttons I can form an xpath similar to this

//input[@type='submit' and @value='Google Search' or @value="I'm Feeling Lucky"]

cssSelector can be used to locate elements by id, class or any other attribute, or combination of those. For example, you can locate the element using

element = driver.findElement(By.cssSelector("#id[value='value1']"));
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!