通过CSS选择器定位元素

以Google主页的搜索按钮为例,其中HTML代码如下:

<input value="Google 搜索" jsaction="sf.chk" name="btnk" type="submit">

对应的CSS路径代码如下:

#st-ib

Selenium WebDriver中通过CSS查找元素的java示例代码如下:

通过CSS选择器查找元素

示例代码详解:

1、使用FirefoxDriver打开Google主页

2、通过CSS路径查找到搜索框。代码如下:

WebElement searchBox = driver.findElement(By.cssSelector("#st-ib"));

3、输入webdriver字符串并进行搜索

相关文章:

  • 2021-12-28
  • 2022-12-23
  • 2021-12-24
  • 2021-12-07
  • 2021-09-07
  • 2022-03-06
  • 2021-12-06
猜你喜欢
  • 2021-12-19
  • 2021-12-27
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-01-04
  • 2021-11-24
相关资源
相似解决方案