我已經編寫了一個腳本來測試一個網站,並且我已經從所有元素的google chrome中取得了Xpath,並且我想在Microsoft Edge上測試它,但是每當我運行它時,我得到一個org.openqa.selenium.remote.ProtocolHandshake createSession
錯誤。所以我的猜測是它無法在Edge上找到元素。來自Chrome的XPath無法在Microsoft Edge上工作
public class testing
{
ExtentHtmlReporter htmlreporter = new ExtentHtmlReporter("D:\\Selenium\\test_report.html");
ExtentReports extent = new ExtentReports();
ExtentTest test;
JavascriptExecutor jse;
WebDriver driver;
@BeforeTest
public void setup()
{
System.setProperty("webdriver.edge.driver", "D:\\Selenium\\MicrosoftWebDriver.exe");
driver = new EdgeDriver();
driver.manage().window().maximize();
extent.attachReporter(htmlreporter);
jse = (JavascriptExecutor)driver;
extent.setSystemInfo("Browseer", "Microsoft Edge");
extent.setSystemInfo("OS", "Windows 10");
driver.get("https://www.hoteltreeoflife.com/reservation");
}
@Test
public void test1()
{
test = extent.createTest("Test Case 1 : Selecting the dates", "Clicking check availabiluty with default dates");
test.info("Finding Check Availability");
driver.findElement(By.xpath("/html/body/div[1]/div[3]/div[2]/div/div/form/div[4]/button")).click(); //<-- This is the element
test.info("Clicks on Check Availability");
String title = driver.getTitle();
Assert.assertTrue(title.contains("Choose Your Room"));
test.info("Successfully selected dates");
}
}
我也找不到在Edge上獲取Xpath的方法。
編輯:
這是完全錯誤:
[TestNG] Running:
Command line suite
[VerboseTestNG] RUNNING: Suite: "Command line test" containing "1" Tests (config: null)
[VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @BeforeTest newpackage.testing.setup()
[16:46:55.985] - Listening on http://localhost:4848/
Jul 26, 2017 4:46:57 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS
[VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @BeforeTest newpackage.testing.setup() finished in 4794 ms
[VerboseTestNG] INVOKING: "Command line test" - newpackage.testing.test1()
[VerboseTestNG] FAILED: "Command line test" - newpackage.testing.test1() finished in 303 ms
[VerboseTestNG] java.lang.AssertionError: expected [true] but found [false]
[VerboseTestNG] at newpackage.testing.test1(testing.java:53)
[VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @AfterMethod newpackage.testing.check(org.testng.ITestResult)(value(s): [TestResult name=test1 status=FAILURE method=testing.test1()[pri:0, instance:[email protected]] output={null}])
[VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @AfterMethod newpackage.testing.check(org.testng.ITestResult)(value(s): [TestResult name=test1 status=FAILURE method=testing.test1()[pri:0, instance:[email protected]] output={null}]) finished in 462 ms
[VerboseTestNG] INVOKING CONFIGURATION: "Command line test" - @AfterTest newpackage.testing.close()
[16:47:03.511] - Stopping server.
[VerboseTestNG] PASSED CONFIGURATION: "Command line test" - @AfterTest newpackage.testing.close() finished in 3788 ms
[VerboseTestNG]
[VerboseTestNG] ===============================================
[VerboseTestNG] Command line test
[VerboseTestNG] Tests run: 1, Failures: 1, Skips: 0
[VerboseTestNG] ===============================================
===============================================
Command line suite
Total tests run: 1, Failures: 1, Skips: 0
===============================================
Java Result: 1
什麼是完整的錯誤?它甚至不能連接到Edge。 –
我不認爲它與查找元素有關。 – NarendraR
@TamasHegedus它連接到Edge並打開URL,但是當點擊元素'driver.findElement(By.xpath(「/ html/body/div [1]/div [3]/div [2]/div/div/form/div [4]/button「))。click();' –