简体   繁体   English

selenium xpath中“//div [.// [text()='Selenium']]”和“// div [// a [text()='SELENIUM']]”之间的区别是什么?

[英]what is the difference between “//div[.//a[text()='SELENIUM']]” and “//div[//a[text()='SELENIUM']]” in selenium xpath

what is the difference between "//div[.//a[text()='SELENIUM']]" and "//div[//a[text()='SELENIUM']]" in selenium xpath. 在selenium xpath中“//div [.// [text()='Selenium']]”和“// div [// a [text()='SELENIUM']]”之间有什么区别?

Can some one please clarify my query on xpath, what is the difference when i give dot(.) before //a and without dot(.) .//a 有人可以澄清我对xpath的查询,当我在// a之前给出点(。)而没有点(。)时,有什么区别.//a

you can use the above mentioned xpath's in this url " http://demo.guru99.com/selenium/guru99home/ " to see the difference. 你可以在这个网址“ http://demo.guru99.com/selenium/guru99home/ ”中使用上面提到的xpath来查看差异。

//x searches the whole tree //x搜索整个树

.//x searches the subtree under the context node .//x搜索上下文节点下的子树

So in a predicate, //div[//x] selects a div if there is an x anywhere in the document, while //div[.//x] selects a div if there is an x within the subtree rooted at that div . 所以在一个谓词中, //div[//x]选择一个div如果文档中有一个x ,而//div[//x] //div[.//x]选择一个div如果在该子树中有一个x div

获取文本<div>使用 Selenium</div><div id="text_translate"><p> 我有一个与 Python 中的 Selenium 相关的问题:</p><p> 我想在网页上获取文本内容“D. New Jersey”。 另外,我想得到的文字在不同的页面上可能会有所不同,但总是在“ <strong>COURT:</strong> ”下。</p><p> HTML 代码为:</p><pre> &lt;div class="span4"&gt; &lt;strong&gt;COURT:&lt;/strong&gt; D. New Jersey &lt;/div&gt;</pre><p> 我现在使用的代码如下。 它不起作用。</p><pre> self.driver.get(address) element=driver.findElement("//a[contains(@class,'span4') and contains(div/div/text(),'COURT:')]").gettext()</pre><p> 我也尝试了以下解决方案,但没有成功,也没有抛出 Selenium 异常:</p><pre> text = self.driver.find_element_by_xpath("//div[strong[text()='COURT:']]").text</pre><p> 和</p><pre>text = self.driver.find_element_by_xpath("//a[contains(@class,'span4') and contains(div/div/text(),'COURT:')]").text</pre><p> 有谁知道如何使用 Selenium 从此代码中获取文本?</p><p> 谢谢</p></div> - Getting text in <div> using Selenium

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium:使用 xpath 在 div 中输入文本 - Selenium : Enter the text in div using xpath 验证之间的文字 <div> 使用硒 - Verifying text between <div> using Selenium Selenium 和 xpath:找到一个带有 class/id 的 div 并验证里面的文本 - Selenium and xpath: finding a div with a class/id and verifying text inside Selenium:使用xpath查找具有特定纯文本的嵌套div - Selenium : Find nested div with specific plain text using xpath 硒,通过其xpath在特定div内查找具有特定文本的跨度? - Selenium, finding a span with specific text inside a specific div by its xpath? 无效选择器:xpath 表达式“//*[@id='topstuff']/div/div/p[1]/text()[2]”的结果是:[object Text] using XPath 和 ZC492C855F06FBB5406D - Invalid selector: The result of the xpath expression “//*[@id='topstuff']/div/div/p[1]/text()[2]” is: [object Text] using XPath and Selenium 获取文本<div>使用 Selenium</div><div id="text_translate"><p> 我有一个与 Python 中的 Selenium 相关的问题:</p><p> 我想在网页上获取文本内容“D. New Jersey”。 另外,我想得到的文字在不同的页面上可能会有所不同,但总是在“ <strong>COURT:</strong> ”下。</p><p> HTML 代码为:</p><pre> &lt;div class="span4"&gt; &lt;strong&gt;COURT:&lt;/strong&gt; D. New Jersey &lt;/div&gt;</pre><p> 我现在使用的代码如下。 它不起作用。</p><pre> self.driver.get(address) element=driver.findElement("//a[contains(@class,'span4') and contains(div/div/text(),'COURT:')]").gettext()</pre><p> 我也尝试了以下解决方案,但没有成功,也没有抛出 Selenium 异常:</p><pre> text = self.driver.find_element_by_xpath("//div[strong[text()='COURT:']]").text</pre><p> 和</p><pre>text = self.driver.find_element_by_xpath("//a[contains(@class,'span4') and contains(div/div/text(),'COURT:')]").text</pre><p> 有谁知道如何使用 Selenium 从此代码中获取文本?</p><p> 谢谢</p></div> - Getting text in <div> using Selenium 在 Selenium + Java 中发送文本到 div - Send text to div in Selenium + Java 用硒获取div元素的文本 - getting text of div element with selenium div之间的硒选择By.Xpath - Selenium selection By.Xpath in between a div
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM