[英]Selenium: do javascript actions reflect in driver.page_source?
If I click on a button that executes some javascript that updates the page (eg adds some html somewhere), will this be reflected in driver.page_source? 如果我单击执行一些JavaScript来更新页面的按钮(例如,在某处添加一些html),这是否会反映在driver.page_source中?
I tried it (clicked on a button that executed some js), waited 10 seconds, and then took a look at driver.page_source and changes do not seem to show up there. 我尝试了一下(单击执行了js的按钮),等待了10秒钟,然后看了一下driver.page_source,那里似乎没有变化。 How can I find out what html was created by that js?
我如何找出该js创建了哪些html?
No, driver.page_source only gives static html code. 不,driver.page_source仅提供静态html代码。 If you want html created by js, you may use
如果要由js创建html,则可以使用
driver.execute_script()
It runs js script and returns the result. 它运行js脚本并返回结果。 Here is an example:
这是一个例子:
element = driver.find_element_by_xpath("//div[@class='WB_feed_type SW_fun S_line2']") #which is created by js
wbHTML = driver.execute_script("return arguments[0].innerHTML;", element)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.