通过ClassName定位元素

以淘宝网的主页搜索框为例,其搜索框的HTML代码如下,ClassName为search-combobox-input

通过ClassNmae查找元素

Selenium WebDriver 中通过ClassName查找淘宝主页上搜索框的java示例代码如下:

通过ClassNmae查找元素

示例代码详解:

1、使用FirefoxDriver来打开淘宝主页

2、通过ClassName为search-combobox-input来调用findElement()方法,找到淘宝主页的搜索框元素并保存到WebElement实例对象中。代码如下:

WebElment searchBox = driver.findElement(By.className("search-combobox-input"));

3、在搜索框中输入字符串test taobao By ClassName并提及进行搜索

相关文章:

  • 2022-12-23
  • 2021-12-11
  • 2022-12-23
  • 2021-08-17
  • 2021-12-26
  • 2021-12-26
  • 2021-12-26
  • 2022-03-03
猜你喜欢
  • 2022-01-20
  • 2021-06-05
  • 2021-08-22
  • 2022-12-23
  • 2021-09-21
相关资源
相似解决方案