代码单击操作登录后,页面将刷新,并且不会重定向到下一页。这仅在该网站上发生,因为我在其他网站上已正确重定向。 当我输入错误的凭证时,甚至不会显示错误消息。(手动有效)
我正在使用Selenium java在Chrome中进行测试。
这是我的代码:
public class Test {
private static final String HTMLPageSourceCode = null;
public static void main(String[] args) throws InterruptedException
{
System.setProperty("webdriver.chrome.driver","C:\\Selenium project\\chromedriver_win32/chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.manage().window().maximize();
driver.get("https://-----/tandem/login");
Thread.sleep(5000);
driver.manage().deleteAllCookies();
driver.findElement(By.id("login")).sendKeys("----");
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.findElement(By.id("password")).sendKeys("----");
WebElement loginbutton = driver.findElement(By.xpath(".//*[@id='login-button']"));
Actions actions = new Actions(driver);
actions.click(loginbutton).perform();
}
}
答案 0 :(得分:0)
要登录网站https://outhouse.inhouseusa.com/tandem/login/
,您需要为elementToBeClickable()
引入 WebDriverWait ,并且可以使用以下Locator Strategies:
代码块:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("start-maximized");
//options.addArguments("disable-infobars");
WebDriver driver = new ChromeDriver(options);
driver.get("https://outhouse.inhouseusa.com/tandem/login/");
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.form-control#login"))).sendKeys("sandy");
driver.findElement(By.cssSelector("input.form-control#password")).sendKeys("sandy");
driver.findElement(By.cssSelector("input.pull-right.button.button-primary#login-button")).click();