【问题标题】:How to pick an element from .XML file in MS edge browser如何在 MS Edge 浏览器中从 .XML 文件中选择元素
【发布时间】:2020-08-11 23:36:18
【问题描述】:
I am trying to get a value(Identifier in my case) from XML to pull some logic rules for a web app. I have managed to get my JavaScript to work on Firefox & Chrome but for Edge, instead of picking an element(Identifier) it's picking an element description from Developers tool.

Test case is:
1. Get an identifier from .XML
2. Go to an application and search using that identifier

For example: .XML
<Application Type="ABCD">
<Identifier>18753</Identifier>
<SalesChannel SalesChannelType="PQRS" SalesChannelSegment="XYZ">
<Identifier>AB1234</Identifier>

My code for this:
driver.get("URL for .XML");
Assert.assertTrue(driver.getPageSource().contains("Identifier"));   

String xml =  driver.getPageSource();
String appID = xml.split("<Identifier>")[1].split("</Identifier>")[0];

**Code to navigate to web app **
driver.findElement(By.id("oData")).sendKeys(appID);

--It uses appID and proceed with an application.

但在这种情况下,它不是选择一个标识符“18753”,而是选择低于值并放入搜索:

{{a xmlns="http://www.w3.org/1999/xhtml" tabindex="-1" role="treeitem" aria-expanded="true" aria-posinset="1" aria- setsize="20" aria-level="2" style="color: blue; margin-left: -2em;">18754

经过调查,我发现这个值来自开发者工具:

【问题讨论】:

  • 你的意思是要使用Edge浏览器查看xml文件,然后,使用selenium获取特殊节点值?为什么不直接在你的应用程序中读取xml文档并获取节点值,然后,使用selenium打开Edge浏览器,根据xml节点值进行搜索。
  • Hi Zhi Lv - MSFT,我不明白分辨率.. 我可以在边缘浏览器中查看/打开 xml 文件,但是在获取 xml 节点值以在 Web 应用程序中搜索时不起作用.. 因此,它不是从 XML 中选择值,而是从开发人员工具中选择节点元素值。虽然相同的代码在 Chrome 和 Firefox 中运行良好。但是在 Edge 中,我没有直接选择节点值,而是直接选择它为什么要打开开发人员工具并从中选择值。
  • 在之前的评论中,我认为我们可以使用C#读取XML节点值(或者使用您的应用程序语言,您可以参考this link),获取节点值后,我们可以使用webdriver打开 Edge 浏览器并导航到网站(您的 Web 应用程序),然后根据节点值查找元素。您可以在String xml = driver.getPageSource(); 中设置调试器并发布“xml”值吗?或许我们可以根据这个值找到解决方法。

标签: selenium microsoft-edge web.xml browser-automation


【解决方案1】:

尝试替换

String appID = xml.split("<Identifier>")[1].split("</Identifier>")[0];

String appID = xml.split("<Identifier>")[0];

【讨论】:

  • 解释为什么您的回答有帮助会显着改善您的回答。
猜你喜欢
  • 2015-05-24
  • 2016-05-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-06-09
  • 2013-09-21
  • 2016-03-05
相关资源
最近更新 更多