我已经编写了一个脚本来测试一个网站,并且我已经从所有元素的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();' –