gpt4 book ai didi

selenium - 在 Internet Explorer 中运行 Selenium 的问题

转载 作者:行者123 更新时间:2023-12-02 20:15:38 25 4
gpt4 key购买 nike

您好,我正在尝试在 IE9 上运行我的 selenium webdriver。

  • 网络驱动程序版本:2.32.0
  • IE:9
  • IEDriverServer_win32:2.32.3
  • Windows7

下面是我的代码:

File IEDriver=new File(System.getProperty("user.dir")+File.separator+"BrowserDrivers"+File.separator+"IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", IEDriver.getAbsolutePath());
DesiredCapabilities cap=DesiredCapabilities.internetExplorer();
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS, true);
WebDriver driver=new InternetExplorerDriver(cap);
driver.get("http://in00616:8421/GS");
Thread.sleep(3000);
//driver.findElement(By.id("j_username")).sendKeys("admin");
//driver.findElement(By.id("j_password")).sendKeys("admin");
driver.findElement(By.xpath(".//input[@id='j_username']")).sendKeys("admin");
driver.findElement(By.xpath(".//input[@id='j_password']")).sendKeys("admin");
driver.findElement(By.id("login")).submit();
Thread.sleep(2000);
driver.findElement(By.xpath(".//button[text()='Securities']")).click();
Thread.sleep(2000);
driver.findElement(By.xpath(".//span[text()='Issue']")).click();
Thread.sleep(2000);
driver.findElement(By.id("tabSecurities_Issue_Request_for_Issues")).click();

以上代码登录到我的网站,但当我尝试单击“证券”按钮时,我无法执行此操作。证券按钮开始闪烁,然后通知我无法找到该元素。

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == .//span[text()='Issue Type'] (WARNING: The server did not provide any stacktrace information) –

相同的代码在 FireFox 中运行良好。

请帮忙,因为我想在 InternetExplorer 上测试我的 UI。我认为是版本兼容性问题。任何人都可以建议 IEDriverServer、Selenium WebDriver 和 IE 的兼容版本集吗?

最佳答案

this SO answer指出,IE 没有 native XPath 支持。相反,当使用 IE 时,Selenium WebDriver 使用旧的第三方 xpath 库。 Firefox 集成了对 XPath 的支持,这就是您的选择器在该浏览器中运行良好的原因。

我强烈建议您更新选择器以改为使用 CSS 选择器。它们受所有浏览器的支持,更容易阅读、理解和掌握,而且速度相当快。

您可以从一些不同的教程中了解有关如何使用 CSS 选择器的更多信息 here , here ,和here ,以及 CSS selectors cheatsheet .

此外,只要有可能,请尽量不要通过元素包含的文本来选择元素。如果您可以通过 ID、类、其他属性甚至通过 DOM 链(即“div.1 > div.2 > span.a > a.b”)来选择元素,这比尝试通过文本选择元素要好.

关于selenium - 在 Internet Explorer 中运行 Selenium 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16687942/

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