请找到以下解决方案。
解决方案
System.setProperty("webdriver.chrome.driver","chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
//driver.manage().timeouts().implicitlyWait(12,TimeUnit.SECONDS);
driver.get("https://in.yahoo.com/");
driver.findElement(By.xpath("//button[@name='agree']")).click();
driver.findElement(By.xpath("//a[@id='uh-signin']")).click();
driver.findElement(By.id("login-username")).sendKeys("Thakur_aju2008@yahoo.com");
driver.findElement(By.id("login-signin")).click();
Thread.sleep(5000);
driver.findElement(By.xpath("//input[@id='login-passwd']")).sendKeys("Pranavpooja@2017");
,
要填充 Yahoo 登录页面https://in.yahoo.com/
中的用户名和密码字段,您需要引入 WebDriverWait 用于elementToBeClickable()
,则可以使用以下任一Locator Strategies:
-
代码块:
-
使用cssSelector
:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
//options.setExperimentalOption("excludeSwitches",Collections.singletonList("enable-automation"));
//options.setExperimentalOption("useAutomationExtension",false);
WebDriver driver = new ChromeDriver(options);
driver.get("https://in.yahoo.com/");
new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a#uh-signin"))).click();
new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.phone-no"))).sendKeys("Thakur_aju2008@yahoo.com");
driver.findElement(By.cssSelector("input#login-signin")).click();
new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input#login-passwd"))).sendKeys("Pranavpooja@2017");
-
使用xpath
:
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
//options.setExperimentalOption("excludeSwitches",20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[@id='uh-signin']"))).click();
new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='phone-no ']"))).sendKeys("Thakur_aju2008@yahoo.com");
driver.findElement(By.xpath("//input[@id='login-signin']")).click();
new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@id='login-passwd']"))).sendKeys("Pranavpooja@2017");
-
浏览器快照:
本文链接:https://www.f2er.com/3160638.html