gpt4 book ai didi

java - 为什么 Selenium 在登录页面后停止?

转载 作者:行者123 更新时间:2023-11-28 21:24:21 28 4
gpt4 key购买 nike

我们已经通过 Selenium 成功登录到应用程序,但是我们不能从那里去任何地方。

Selenium 从那时起停止工作。

这是我们用来进入应用程序的代码:

public class testclass {

public static void main(String[] args) {
System.setProperty("webdriver.gecko.driver", "C:\\Selenium-java-3.0.1\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
// this will create an object for the Firefox profile
FirefoxProfile myprofile = profile.getProfile("default");
// this will Initialize the Firefox driver
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("https://applicationURL/Forms");
driver.findElement(By.xpath(".//*[@id='login']")).click();
driver.findElement(By.xpath(".//*[@id='login']")).sendKeys("username");
driver.findElement(By.xpath(".//*[@id='password']")).click();
driver.findElement(By.xpath(".//*[@id='password']")).sendKeys("password");
driver.findElement(By.xpath(".//*[@id='btnlogin']")).click();

[这是 Selenium 停止的地方]

     driver.findElement(By.xpath(".//*[@id='panelBarMiddleSearchPanels_i0_txtAttr_1_22']")).click();
driver.findElement(By.xpath(".//*[@id='panelBarMiddleSearchPanels_i0_txtAttr_1_22']")).sendKeys("LTR*");

}

然后我不知道在哪里可以找到 Selenium 得到的错误?因为它只是停在需要更进一步的地方。

我不确定是否值得一提,但我们正在通过 VPN 工作。我不确定它是否与此问题有关 -- Can't open browser with Selenium after Firefox update

最佳答案

尝试使用以下更新代码:

   public class testclass {

public static void main(String[] args) throws Exception{
System.setProperty("webdriver.gecko.driver", "C:\\Selenium-java-3.0.1\\geckodriver.exe");
ProfilesIni profile = new ProfilesIni();
// this will create an object for the Firefox profile
FirefoxProfile myprofile = profile.getProfile("default");
// this will Initialize the Firefox driver
WebDriver driver = new FirefoxDriver(myprofile);
driver.get("https://applicationURL/Forms");
driver.findElement(By.xpath(".//*[@id='login']")).click();
driver.findElement(By.xpath(".//*[@id='login']")).sendKeys("username");
driver.findElement(By.xpath(".//*[@id='password']")).click();
driver.findElement(By.xpath(".//*[@id='password']")).sendKeys("password");
driver.findElement(By.xpath(".//*[@id='btnlogin']")).click();
Thread.sleep(7000);
driver.findElement(By.xpath(".//*[@id='panelBarMiddleSearchPanels_i0_txtAttr_1_22']")).click();
driver.findElement(By.xpath(".//*[@id='panelBarMiddleSearchPanels_i0_txtAttr_1_22']")).sendKeys("LTR*");

}

希望对你有所帮助。

关于java - 为什么 Selenium 在登录页面后停止?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44454513/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com