Tag: xpath

JAVA – 如何在selenium中使用xpath

我有这个HTML代码: «Seleziona la categoria» — VEICOLI — Auto 我必须选择标签option标识的WebElement文本Auto 。 我尝试了一些解决方案: d.findElement(By.xpath(“/select[@id=category]/option[@id=cat2]”)).click(); d.findElement(By.xpath(“/select[@id=category]/option[text()=’Auto’]”)).click(); d.findElement(By.xpath(“//select[@id=category]/option[Auto]”)).click(); 但每个人都给了我: Exception in thread “main” org.openqa.selenium.NoSuchElementException: Unable to locate element: {“method”:”xpath”,”selector”:”/select[@id=category]/option[@id=cat2]”} ( and other xpath i tried) Command duration or timeout: 1.52 seconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html 什么是正确的语法? 有人能帮我吗?

每次加载页面gest后,Xpath都会发生变化

我正在使用Selenium WebDriver和Java。 我正在尝试访问该页面中的“登录ID”文本框,但每次登录和注销时,“登录ID”文本框的XPath值都会更改,因此我无法检测到“登录ID”文本框每次使用相同的代码。 我需要在代码中进行哪些修改才能使用一段代码访问所有动态XPath?

XPath,XML命名空间和Java

我花了一天时间尝试从以下文档中提取一个XML节点,并且无法掌握XML命名空间的细微差别以使其工作。 XML文件总数很大,所以这是我关注的部分: HAND RECEIPT/ANNEX NUMBER 该文件继续存在并且形成良好。 我试图从“documentnbr”标签中提取“数字”属性(从底部三个)。 我用来执行此操作的代码如下所示: /*** * Locates the Document Number information in the file and returns the form number. * @return File’s self-declared number. * @throws InvalidFormException Thrown when XPath cannot find the “documentnbr” element in the file. */ public String getFormNumber() throws InvalidFormException { try{ XPath xPath = XPathFactory.newInstance().newXPath(); xPath.setNamespaceContext(new […]

XPath使用defaultNamespace为xml返回null

我相信它在不久前工作但现在xpath返回null。 有人可以帮我在下面的代码中找到我的愚蠢错误吗? 或者我甚至必须在setNamespaceAware(false)之后提供NamespaceContext? DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); domFactory.setNamespaceAware(false); domFactory.setIgnoringComments(true); domFactory.setIgnoringElementContentWhitespace(true); try { Document doc = domFactory.newDocumentBuilder().parse(new File(“E:/Temp/test.xml”)); XPath xp = XPathFactory.newInstance().newXPath(); NodeList nl = (NodeList) xp.evaluate(“//class”, doc, XPathConstants.NODESET); System.out.println(nl.getLength()); }catch (Exception e){ e.printStackTrace(); } XML文档在这里:

使用StAX和XPath读取大量XML文件

输入文件包含数千个XML格式的事务,大小约为10GB。 要求是根据用户输入选择每个事务XML并将其发送到处理系统。 文件的示例内容 product 1 29.99 product 2 59.59 (技术)用户应该给出输入标签名称,如 。 我们希望提供更通用的解决方案。 文件内容可能不同,用户可以提供类似“ //transactions/txn ”的XPath表达式来选择单个事务。 我们在这里需要考虑的技术问题很少 该文件可以位于共享位置或FTP中 由于文件很大,我们无法在JVM中加载整个文件 我们可以在这种情况下使用StAX解析器吗? 它必须将XPath表达式作为输入并选择/选择事务XML。 寻找建议。 提前致谢。

在Java中使用SAXON Xpath引擎

这是我的代码: public static void main(String[] args) { // System.setProperty( // “javax.xml.xpath.XPathFactory”, // “net.sf.saxon.xpath.XPathFactoryImpl”); String xml=”#BBB##CCC##DDD#”; try{ JDocument dom = new JDocument(xml); XPathFactory factory = net.sf.saxon.xpath.XPathFactoryImpl.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile(“//a[matches(.,’#…#’)]”); Object result = expr.evaluate(dom, XPathConstants.NODESET); NodeList nodes = (NodeList) result; Nodes sharped = new Nodes(nodes); for (Node n:sharped){ System.out.println(n.toString()); } } catch(Exception […]

如何从一组XPath表达式生成XML文件?

我希望能够在给定一组XPath映射的情况下生成完整的XML文件。 输入可以在两个映射中指定:(1)一个列出XPath表达式和值; (2)定义适当名称空间的另一个。 /create/article[1]/id => 1 /create/article[1]/description => bar /create/article[1]/name[1] => foo /create/article[1]/price[1]/amount => 00.00 /create/article[1]/price[1]/currency => USD /create/article[2]/id => 2 /create/article[2]/description => some name /create/article[2]/name[1] => some description /create/article[2]/price[1]/amount => 00.01 /create/article[2]/price[1]/currency => USD 对于名称空间: /create => xmlns:ns1=’http://predic8.com/wsdl/material/ArticleService/1/ /create/article => xmlns:ns1=’http://predic8.com/material/1/’ /create/article/price => xmlns:ns1=’http://predic8.com/common/1/’ /create/article/id => xmlns:ns1=’http://predic8.com/material/1/’ 另请注意,我也必须处理XPath 属性表达式。 例如:我还应该能够处理属性,例如: /create/article/@type => richtext 最终的输出应该是这样的: […]

xpath 2.0 for java possible

我应该为XPath使用什么包? 我想要查询元素,然后在这些节点周围提取一些值。 也许一个或多个级别更高,一些属性。 javax.xml.xpath是XPath 1.0。 javax.xml.xpath和org.w3c.dom是正确的方法,还是有更现代的实现? org.w3c.dom很尴尬,JDOM看起来很简单。

如何在java中的某个元素之后/之前将元素插入到xml中

这是我的代码,也许你会马上注意到我缺少的东西: DocumentBuilderFactory domFactory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = domFactory.newDocumentBuilder(); Document doc = builder.parse(fileName)); XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); XPathExpression expr = xpath.compile(“//CustomerId”); Object result = expr.evaluate(doc, XPathConstants.NODESET); Nodelist nodes = (NodeList) result; Text a = doc.createTextNode(“value”); Element p = doc.createElement(“newNode”); p.appendChild(a); for (int i = 0; i < nodes.getLength(); i++) { nodes.item(i).insertBefore(p, […]

我使用的是哪个版本的XPATH和XSLT ..?

如何知道我使用的是哪个版本的XPATH和XSLT? 说我已经安装了JDK 1.7然后我有哪个版本的XPATH和XSLT ..?