以下行给出错误:
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//input[@id='username']")));
代码如下:
WebDriverManager.chromedriver().setup();
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("--disable-notifications");
ChromeDriver driver = new ChromeDriver(options);
driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);
driver.get("https://test.salesforce.com/");
WebDriverWait wait=new WebDriverWait(driver, 120);
driver.findElement(By.id("username")).sendKeys("");
driver.findElement(By.id("password")).sendKeys("");
driver.findElement(By.id("Login")).click();
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[contains(@class,'home-accounts')]")));**
此外,我还观察到:
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[contains(@class,'home-accounts')]")));
工作得很好。
怎么处理呢?
堆栈跟踪:
java.lang.NullPointerException
at org.openqa.selenium.remote.RemoteWebElement.isDisplayed(RemoteWebElement.java:323)
at org.openqa.selenium.support.ui.ExpectedConditions.elementIfVisible(ExpectedConditions.java:315)
at org.openqa.selenium.support.ui.ExpectedConditions.access$100(ExpectedConditions.java:44)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:206)
at org.openqa.selenium.support.ui.ExpectedConditions$7.apply(ExpectedConditions.java:202)
at org.openqa.selenium.support.ui.FluentWait.until(FluentWait.java:248)
at TestClass.NewTest.TC_DealDetails_0(NewTest.java:70)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:124)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:583)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:719)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:989)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:125)
at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:648)
at org.testng.TestRunner.run(TestRunner.java:505)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:455)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:450)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:415)
at org.testng.SuiteRunner.run(SuiteRunner.java:364)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:84)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1208)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1137)
at org.testng.TestNG.runSuites(TestNG.java:1049)
at org.testng.TestNG.run(TestNG.java:1017)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:115)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:251)
at org.testng.remote.RemoteTestNG.main(RemoteTestNG.java:77)
发布于 2019-09-27 05:28:41
WebDriverManager
WebDriverManager允许自动管理二进制驱动程序(例如chromedriver、geckodriver等)Selenium WebDriver需要。添加以下行:
WebDriverManager.chromedriver().setup();
WebDriverManager为您执行以下任务:
~/.m2/repository/webdriver
),则它会下载该文件。接下来,您需要使用WebDriver接口,而不是从ChromeDriver类创建driver
。因此,您需要替换:
ChromeDriver driver = new ChromeDriver(options);
通过以下方式:
WebDriver driver = new ChromeDriver(options);
https://stackoverflow.com/questions/58120464
复制相似问题