Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/335.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何通过Selenium和Python使用xpath精确计算数字_Python_Selenium_Selenium Webdriver_Xpath_Webdriver - Fatal编程技术网

如何通过Selenium和Python使用xpath精确计算数字

如何通过Selenium和Python使用xpath精确计算数字,python,selenium,selenium-webdriver,xpath,webdriver,Python,Selenium,Selenium Webdriver,Xpath,Webdriver,您好,我正在尝试查找包含文本“01.0000”的元素,但此行前有一个包含“01.00”的源代码。如何定位此元素 源代码: <div class="gofer-search-results"> <a href="#" class="js-hovered"><span class="name">Communication and Media Studies</span><span class="code">09.01</span>

您好,我正在尝试查找包含文本“01.0000”的元素,但此行前有一个包含“01.00”的源代码。如何定位此元素

源代码:

<div class="gofer-search-results">
<a href="#" class="js-hovered"><span class="name">Communication and Media Studies</span><span class="code">09.01</span></a>
<a href="#" class=""><span class="name">Communication, General</span><span class="code">09.0100</span></a>
<a href="#" class=""><span class="name">Speech Communication and Rhetoric</span><span class="code">09.0101</span></a>
<a href="#" class=""><span class="name">Mass Communication/Media Studies</span><span class="code">09.0102</span></a>
<a href="#" class=""><span class="name">Communication and Media Studies, Other</span><span class="code">09.0199</span></a>
<a href="#" class=""><span class="name">Animal Sciences</span><span class="code">01.09</span></a></div>

我一直使用01.00元素而不是01.0000元素。

要使用文本定位此元素为01.0000,可以使用以下任一解决方案:

  • 使用text():

  • 使用normalize-space():


请在文本中添加源代码,还请添加您发现的错误。刚刚完成。感谢这对我有用
[x代表驱动程序中的x。如果x.text='09.0100']
我忘了输入',请通过xpath(“//div/a/span”)查找元素。谢谢!
driver.find_element_by_xpath("//span/div/a/span[text()= 01.0000]")
driver.find_element_by_xpath("//span/div/a/span[normalize-space()= 01.0000]")
driver.find_element_by_xpath("//span/div/a/span[./text()= 01.0000]")
driver.find_element_by_xpath("//span/div/a/span[text()='01.0000']")
driver.find_element_by_xpath("//span/div/a/span[normalize-space()='01.0000']")