问题描述
希望你一切都好.我是硒的新手,也是堆栈溢出的新手,所以我希望我没有违反这里的任何规则.
Hope you're all well. I'm quite new to selenium and a complete newbie to stack overflowso i hope i'm not disobeying any rules here.
我正在尝试使用以下内容创建一个测试框架和一些测试
I am trying to create a test framework and some tests using the following
c#、selenium webdriver、specflow、nunit
c#, selenium webdriver, specflow, nunit
我目前正在对 sql server 数据库运行查询以检索一些文本,然后尝试使用该文本来验证和搜索站点上的该元素.我的问题是该网站的元素 html 已编码
I am currently running a query against a sql server DB to retrieve some text and then trying to use that text to verify and search for that element on the site. The problem i have is that the site has the element html encoded
例如:
从数据库中检索到的数据可能类似于 - Alumina MB China Metallurgical Grade Delivered...."
Data retrieved from the database could be something like - "Alumina MB China metallurgical grade delivered...."
网站上的元素如下-
<span class="com">Alumina MB China metallurgical grade delivered duty paid RBM/tonne</span>
有谁知道我如何将从数据库检索到的数据解析为 findElement 命令,以便在包含
Does anyone know how i could parse the data retrieved from the DB into the findElement command to easily find this element on the site whilst it contains
期待您的回音.
非常感谢苏班
推荐答案
尝试使用 System.Web.HttpUtility.HtmlDecode
它对我有用:
var escaped = System.Web.HttpUtility.HtmlDecode(".//span[text()='Alumina MB China metallurgical grade delivered duty paid RBM/tonne']");
IWebElement element = driver.FindElement(By.XPath(escaped));
这篇关于使用 Selenium webdriver 查找带有 &nbsp; 的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!