回答

收藏

技术问答测试

技术问答 技术问答 189 人阅读 | 0 人回复 | 2023-08-08

  1. import org.openqa.selenium.By;
  2. import org.openqa.selenium.WebDriver; + t  L, {# {8 o9 T. D
  3. import org.openqa.selenium.WebElement;
  4. import org.openqa.selenium.chrome.ChromeDriver; : R% X& {6 F# k* _& B; t+ N# r% _$ V
  5. import org.openqa.selenium.chrome.ChromeOptions; ) K2 J+ @/ P% L$ u9 `7 l
  6. 7 X) S8 c3 X3 A- I
  7. public class Main {
  8.     public static void main(String[] args) { & @; l. H/ A2 H& O
  9.         ChromeOptions options=new ChromeOptions(); ( M, b& H+ P! i$ F4 u3 B. L
  10.         options.addArguments("--remote-allow-origins=*"); & k( f8 y, M) Y- F. M
  11.         WebDriver webDriver=new ChromeDriver(options);
  12.         webDriver.get("https://www.baidu.com/"); , _, X9 ]4 Z8 a& Q- X( S
  13.         //定位元素 , |/ h& S6 [  ~/ f4 H# z
  14.         //找到百度搜索框
  15.        WebElement element = webDriver.findElement(By.cssSelector(".s_ipt"));
  16.        //输入软件测试
  17.         element.sendKeys("软件测试");
  18.     }
  19. }
复制代码

1 f. K2 V  h2 W# o. C( g5 Y- g3 u0 v% P/ u3 ^/ k
我知道答案 回答被采纳将会获得5 金钱 已有0人回答
分享到:
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则