使用Selenium的文本和innerHTML之间的区别 [英] Difference between text and innerHTML using Selenium

查看:424
本文介绍了使用Selenium的文本和innerHTML之间的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用硒时获取textinnerHTML有什么区别?即使我们在特定元素下有文本,当执行.text时,我们也会得到空值.但是执行.get_attribute("innerHTML")可以正常工作.

Whats the difference between getting text and innerHTML when using selenium. Even though we have text under particular element, when we perform .text we get empty values. But doing .get_attribute("innerHTML") works fine.

有人可以指出两者之间的区别吗?何时应该在.text上使用'.get_attribute("innerHTML")'?

Can someone point out the difference between two? When someone should use '.get_attribute("innerHTML")' over .text?

推荐答案

.text将检索视口中不存在的文本的空字符串,因此您可以将对象滚动到视口中并尝试.text检索值.

.text will retrieve an empty string of the text in not present in the view port, so you can sroll the object into the viewport and try .text it should retrive the value.

相反,innerhtml可以获取值,即使该值出现在视图端口之外

On the contrary innerhtml can get the value even of it is present out side the view port

这篇关于使用Selenium的文本和innerHTML之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆