gpt4 book ai didi

java - IEDriver 始终显示 localhost 标题而不是给定的 URL 标题

转载 作者:太空宇宙 更新时间:2023-11-04 11:16:18 25 4
gpt4 key购买 nike

当驱动程序启动浏览器时,它总是与本地主机打开然后导航到给定的 URL,但驱动程序未获取当前页面标题而不是始终显示本地主机标题“此页面不能显示”。我正在发布我的代码和我收到的错误,请告诉我我哪里错了。

import java.util.concurrent.TimeUnit;  
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.ie.InternetExplorerDriver;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

public class TestIEBrowser {

公共(public) WebDriver 驱动程序;

    @BeforeClass
public void setUp() {
System.out.println("*******************");
System.out.println("launching IE browser");
System.setProperty("webdriver.ie.driver", "C:\\IEDriverServer_Win32_2.39.0\\IEDriverServer.exe");
driver = new InternetExplorerDriver();
driver.manage().window().maximize();
}

@Test(priority=1)
public void testGooglePageTitleInIEBrowser() {
driver.navigate().to("http://www.google.com");
driver.manage().timeouts().implicitlyWait( 30, TimeUnit.SECONDS );
String strPageTitle = driver.getTitle();
System.out.println("Page title: - "+strPageTitle);
Assert.assertTrue(strPageTitle.equalsIgnoreCase("Google"),
"Page `title doesn't match");`
}

@AfterClass
public void tearDown() {
if(driver!=null) {
System.out.println("Closing IE browser");
driver.quit();
}
} }

Error
launching IE browser
Started InternetExplorerDriver server (32-bit) 2.39.0.0
Listening on port 47579
Jul 31, 2017 5:43:08 PM org.openqa.selenium.remote.ProtocolHandshake createSession

INFO: Detected dialect: OSS

Page title: - This page can’t be displayed

Closing IE browser

FAILED: testGooglePageTitleInIEBrowser

java.lang.AssertionError: Page title doesn't match expected [true] but found [false]

at org.testng.Assert.fail(Assert.java:93)

at org.testng.Assert.failNotEquals(Assert.java:512)

at org.testng.Assert.assertTrue(Assert.java:41)
at TestIEBrowser.testGooglePageTitleInIEBrowser(TestIEBrowser.java:30)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)

at org.testng.internal.Invoker.invokeMethod(Invoker.java:661)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:869)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1193)
at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:126)

at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:109)
at org.testng.TestRunner.privateRun(TestRunner.java:744)
at org.testng.TestRunner.run(TestRunner.java:602)
at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
at org.testng.SuiteRunner.run(SuiteRunner.java:289)
at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
at org.testng.TestNG.runSuites(TestNG.java:1144)
at org.testng.TestNG.run(TestNG.java:1115)
at org.testng.remote.AbstractRemoteTestNG.run(AbstractRemoteTestNG.java:132)
at org.testng.remote.RemoteTestNG.initAndRun(RemoteTestNG.java:230)

最佳答案

尝试使用 driver.get() 而不是 driver.navigate()。

您也可以尝试使用

WebDriverWait 等待 = new WebDriverWait(driver, 30);
wait.until(title.isDisplayed)

关于java - IEDriver 始终显示 localhost 标题而不是给定的 URL 标题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45431260/

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