Tag: xpath

Spring int-xml:带路径函数的xpath-expression错误

我使用XMLSpy编写以下XPath来确定最长的字符串长度,它在XMLSpy中工作: string-length(//exception:ElementMessageAbcException/@exceptionMsg[not(string-length(.) < //exception:ElementMessageAbcException/@exceptionMsg/string-length(.))] ) 但是当我在Spring集成中将相同的字符串放入xpath-expression时,它会出错: org.springframework.beans.factory.BeanCreationException:创建名为’xpathMaxLengthExceptionMsg’的bean时出错:bean的实例化失败; 嵌套exception是org.springframework.beans.factory.BeanDefinitionStoreException:工厂方法[public static org.springframework.xml.xpath.XPathExpression org.springframework.xml.xpath.XPathExpressionFactory.createXPathExpression(java.lang.String,java.util.Map)抛出java.lang.IllegalStateException,org.springframework.xml.xpath.XPathParseException]抛出exception; 嵌套exception是org.springframework.xml.xpath.XPathParseException:无法编译[//exception:MarkitMessageAciException / @ exceptionMsg [not(string-length()<//异常:MarkitMessageAciException / @ exceptionMsg / string-length())]到XPathExpression:null; 嵌套异常是javax.xml.xpath.XPathExpressionException引起:javax.xml.transform.TransformerException:未知nodetype:string-length 示例XML:

等待页面元素(xpath)在Selenium Webdriver中显示的最有效方法是什么?

我正在使用Java和Selenium Webdriver来测试单页Web应用程序的function。 因此,很明显,元素会动态地从DOM中注入和删除。 我知道我可以使用类似的代码使用WebDriverWait等待一个元素出现在DOM中(非常简洁的模板我写了稍微改变的GitHub ): public void waitForElement() throws Exception { /* Inject the following snippet in any web page to test the method Press me */ System.setProperty(“webdriver.gecko.driver”, “C:\\Program Files (x86)\\Mozilla Firefox\\geckodriver.exe”); WebDriver driver = getDriver(); WebDriverWait wait = new WebDriverWait(driver, 10); // 10 can be reduced as per Test Specifications driver.get(“http://www.google.com”); WebElement response = […]

使用xpath和jdom选择节点

我有一个xform文档 Summary 我想使用xpath和jdom从xform中选择数据元素 XPath xpath = XPath.newInstance(“h:html/h:head/h:title/”); 似乎工作正常,并选择标题元素,但 XPath xpath = XPath.newInstance(“h:html/h:head/model”); 不选择模型元素。 我想这与命名空间有关。

线程“main”中的exceptionorg.openqa.selenium.NoSuchElementException:无法找到element:// *

我不得不重新测试xpath ,以前它工作正常,但现在它给了我一个错误。 我尝试过不同的定位器,比如id , name 。 但仍然得到相同的错误。 package staging; import org.openqa.selenium.By; import org.openqa.selenium.WebDriver; import org.openqa.selenium.firefox.FirefoxDriver; public class login { public static void main (String[]args){ System.setProperty(“webdriver.gecko.driver”,”C:\\Program Files\\geckodriver.exe”); WebDriver driver = new FirefoxDriver(); //opening the browser driver.get(“https://staging.keela.co/login”); //logging driver.findElement(By.xpath(“//*[@id=’login-email’]”)).sendKeys(“bandanakeela@yopmail.com”); driver.findElement(By.xpath(“//*[@id=’login-password’]”)).sendKeys(“keela”); driver.findElement(By.xpath(“//*[@id=’login-form’]/div[3]/div/button”)).click(); } }

WebDriver无法使用Java通过xpath找到元素

以下是使用Java的WebDriver代码片段: WebDriver driver = new FirefoxDriver(); driver.get(“http://www.google.pl/”); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); WebElement element = driver.findElement(By.name(“q”)); driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS); WebElement query = driver.findElement(By.xpath(“//html/body/div[2]/span/center/form/table/tbody/tr/td[2]/div/div/input”)); query.sendKeys(“asd”); 执行代码后,我得到以下exception: 线程“main”中的exceptionorg.openqa.selenium.NoSuchElementException:无法定位元素:{“method”:“xpath”,“selector”:“// html / body / div [2] / span / center / form / table / tbody / tr / td [2] / div / div / input“}系统信息:os.name:’Windows 7’,os.arch:’x86’,os.version:’6.1’,java.version: ‘1.6.0_24’驱动程序信息:driver.version:sun.reflect.NativeConstructorAccessorImpl.newInstance0(本地方法)中的sun.reflect.NativeConstructorAccessorImpl.newInstance(未知来源)位于sun.reflect.DelegatingConstructorAccessorImpl.newInstance(未知来源)处的RemoteWebDriver org.openqa.selenium.remote上的org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:131)中的java.lang.reflect.Constructor.newInstance(未知来源).ErrorHandler.throwIfResponseFailed(ErrorHandler.java:105 )org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:409)org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:192)at org.openqa.selenium.remote.RemoteWebDri ver.findElementByXPath(RemoteWebDriver.java:265)atg.openqa.selenium.By […]

如何使用xpath编辑特定的xml

我有以下xml,使用xslt函数json-to-xml()生成。 我需要使用给定的xpath更新此xml,如结果xml中所示。 我需要java或xslt中的解决方案。 任何帮助将非常感激。 XML Lisa 200 applicaton/json ccc mmm 666 333 abc 2018 的XPath /Response/Payload/root/cars[2]/strength=999 /Response/Payload/root/bikes/model=2019 /Response/Headers/server=WebSphere /Response/Headers/Content-Type=text /Response/Payload/root/cars[2]/Capacity=555 /Response/Payload/root/cars[1]/model=mmm1 /Response/Payload/root/bikes/company=xyz /Response/Payload/root/cars[1]/company=ccc1 /Response/Headers/Status-Code=400 更新的结果XML WebSphere 400 text ccc1 mmm1 999 555 xyz 2019 我的尝试 我尝试使用xslt函数将此xml转换回json,然后使用com.jayway.jsonpath Jayway JsonPath库来解析/更改给定xpath上的json值。 然后最后使用xslt函数将json再次更改为xml。 这对我来说就像魅力一样! 但是在使用这个库之后我开始在我的应用程序的其他部分遇到问题:(。所有json请求体的发布请求开始给出400错误。错误是“错误400客户端发送的请求在语法上不正确”。我不能找出问题并且可能是由于不同的jar骗局。所以我正在尝试其他方式工作。任何其他库如Jayway JsonPath?或任何其他解决方案/建议将帮助很多。

获取元素的XPath列表

我有具有特定名称的元素的NodeList,我想拥有所有theese节点的XPath。 我找不到如何做到这一点的方法。 NodeList nList = doc.getElementsByTagName(“definition”); for (int i = 0; i < nList.getLength(); i++) { Node node = nList.item(i); System.out.println(node.GET_XPATH()); } 我正在寻找像GET_XPATH()这样的方法 有人知道怎么做吗? 或者甚至可能吗? 如果有可能,XSLT也可以使用它,但更喜欢有人知道Java中的这种可能性。 原因:我需要一组指向XML库的指针。 用于定义元素的指针。 示例输入: experiment Experiment 输出: /odML/section/definition /odML/section/property[1]/definition /odML/section/property[2]/definition /odML/section/property[2]/value/definition /odML/definition

使用XPath单击超文本链接

抱歉,如果这是一个愚蠢的问题 – 我是Selenium的新手。 我有一个我正在测试的网页,它在表格中有一些超文本链接。 HTML看起来像这样: History Attributes Xml Show Show Show 我想测试每个“显示”链接上的点击。 它们都有相同的文本,所以我不能通过https://stackoverflow.com/questions/13076765/clicking-on-a-hypertext-link-using-xpath/linktext引用它们。 我一直在用XPath引用它们,所以: driver.findElement(By.xpath(“//div[@id=’content’]/div/form/div/table[2]/thead/tr/td[1]”).getText() 正确地返回’历史’和 driver.findElement(By.xpath(“//div[@id=’content’]/div/form/div/table[2]/tbody/tr/td[1]”).getText() 正确返回’显示’。 所以我认为: driver.findElement(By.xpath(“//div[@id=’content’]/div/form/div/table[2]/tbody/tr/td[1]”)).click() 将点击第一列中的“显示”链接。 但它没有 – 没有任何反应。 如果我做: driver.findElement(By.https://stackoverflow.com/questions/13076765/clicking-on-a-hypertext-link-using-xpath/linkText(“Show”)).click() 它会点击第一个“显示”链接,这是我所期望的。 我也可以这样做: driver.findElement(By.xpath(“//div[@id=’content’]/div/form/div/table[2].1.0”)).click() 这是有效的 driver.findElement(By.xpath(“(//a[contains(text(),’Show’)])[2]”)).click() 所以,总而言之,所有这些工作: driver.findElement(By.https://stackoverflow.com/questions/13076765/clicking-on-a-hypertext-link-using-xpath/linkText(“Show”)).click() driver.findElement(By.xpath(“//div[@id=’content’]/div/form/div/table[2].1.0”)).click() driver.findElement(By.xpath(“(//a[contains(text(),’Show’)])[1]”)).click() 但这不是: driver.findElement(By.xpath(“//div[@id=’content’]/div/form/div/table[2]/tbody/tr/td[1]”)).click() 为什么?

使用xpath和java解析xml

现在我想解析来自webservice的xml。 对于解析,我使用了xpath和java。 我有以下代码: package test.client; import com.sun.org.apache.xpath.internal.NodeSet; import java.io.FileReader; import java.io.StringReader; import javax.lang.model.element.Element; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; import javax.xml.xpath.XPathFactory; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; public class GetAlarmsCriticalDataCenterLinksDown { public static void main(String args[]) throws Exception { try { GetAlarms ga = new GetAlarms(); String xml = ga.getAlarms( “Alarms”, “C:/Documents and Settings/Administrator/My Documents/NetBeansProjects/WebSpectrumDemo/src/java/com/xml/Alarms/GetAlarmsCriticalDataCenterLinksDown.xml”); System.out.println(“Response XML:\n ” + […]

Selenium – 使用xpath获取文本节点并将其用作Java中的字符串

我有一段这样的代码: * Question 1 我想将问题1存储为Java中的字符串,因此当我使用xpath //div/text()来获取文本“问题1”时。 但是,当我尝试打印该值时,我收到错误无效选择器exceptionXpath // div / text()是:[object Text]。 它应该是一个元素。 String text = driver.findElement(By.xpath(“//div”)).getText(); //返回*问题1 String text = driver.findElement(By.xpath(“//div/text()”)).getText(); //返回错误 我应该如何存储问题1.我可以使用上面的第一种方法替换*,但我不想这样做。