Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/338.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.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
Python Can';无法在强标记中获取文本_Python_Selenium - Fatal编程技术网

Python Can';无法在强标记中获取文本

Python Can';无法在强标记中获取文本,python,selenium,Python,Selenium,如果文本不在查看端口中或未显示,是否可以尝试打印textContent属性: <div class="some_class> <p> <strong> some text </strong> </p> </div> 你也可以试试 driver.find_element_by_xpath("xpath to strong tab").get_attribu

如果文本不在查看端口中或未显示,是否可以尝试打印textContent属性:

<div class="some_class>    
  <p>
   <strong>
     some text
   </strong>
  </p>
</div>
你也可以试试

 driver.find_element_by_xpath("xpath to strong tab").get_attribute("textContent")

这将使元素进入视图

页面中可能有多个
选项卡

请尝试以下操作:

strong = driver.find_element_by_xpath("xpath to strong tab")
driver.execute_script("arguments[0].scrollIntoView()",strong)
print(strong.text)

如果正确地捕捉路径,则不会出现任何错误。检查xpath内部使用的路径。我检查了路径,所有内容都是正确的。我能够从上面的另一个p标签中获取文本,但该标签内部没有一个强标签帮助我们帮助您-请改进您的问题,以便我们能够重现您的问题。如何创建感谢---请提供更多信息。p标记中只有1个强标记第一种方法有效,ty
allStrongs = driver.find_elements_by_xpath("xpath to strong tab")

for aStrong in allStrongs:

     print(aStrong.text)