Selenium测试本地字符串

Selenium测试本地字符串,selenium,Selenium,我没有从服务器获取HTML,而是在内存中已经有了HTML字符串,我想使用Selenium来检查它的内容。这可能吗?如果愿意,您可以将本地html文件作为字符串或本地txt文件进行操作 以下是如何在Ruby中实现这一点: require 'open-uri' require 'nokogiri' # *** open a URL as a string or as a local txt file # *** strip the file out of unnecessary html tag

我没有从服务器获取HTML,而是在内存中已经有了HTML字符串,我想使用Selenium来检查它的内容。这可能吗?

如果愿意,您可以将本地html文件作为字符串或本地txt文件进行操作

以下是如何在Ruby中实现这一点:

require 'open-uri'
require 'nokogiri'

# *** open a URL as a string or as a local txt file 
# *** strip the file out of unnecessary html tags and encode chars ***

$url = driver.current_url    
$txt_file = open($url)


$raw_contents = $txt_file.read    
$html = Nokogiri::HTML(CGI.unescapeHTML($raw_contents)).content
#here we strip the web page fetched out of all hmtl tags and encoded chars


$txt_file = File.new('c:\ruby193\bin\web-content\web_read.txt', "w") 
#web_read.txt should now contain a stripped, pure txt file

$txt_file.write($html)
$txt_file.close

您是否在本地提供html?如果是这样,您可以使用selenium将浏览器指向localhost。我想您正在寻找Nokogiri gem。你打算做一些屏幕报废吗?我一直在本地处理html文件,去掉不必要的字符,并将它们保存为字符串或本地文本文件。