[英]Selenium webdriver get value from data-bind on span tag
I need to get the value from this tag 我需要从此标签获取值
<span>
<a class="jsk-sa-dialog link-lightbox-valores" data-bind="attr: { href: '#sa-valor-' + $root.types().id }" href="#sa-valor-2">
Link to click that pop-ups a new window
</a>
</span>
After look at the "html" code in debugger, I saw the text that I want to get into HTML... To get the text that is generated into the popup window, I wrote this code: 在调试器中查看“ html”代码后,我看到了要添加到HTML中的文本...要获取在弹出窗口中生成的文本,我编写了以下代码:
case "someBaseText":
{
details.Click(); // Simulate the click on <a> tag
var tx = details.FindElement(By.XPath("//div[@class='overview-material']"));
var dv = tx.FindElement(By.XPath("//div[@class='sa-valor']/h3"));
var ttText = dv.Text; // Empty :(
}
The HTML that i got from debugger: 我从调试器获得的HTML:
<div class="overview-material">
<div class="valores" data-bind="foreach: $root.types">
<div class="sa-valor" data-bind="attr: { id: 'sa-valor-' + id }" id="sa-valor-2">
<h3 class="titulo">Mensalidade</h3>
<div class="texto" data-bind="html: apresentacao.valor">
TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT TEXT
So, I want to get the text inside of div class "texto" 所以,我想在div类“ texto”中获取文本
Based on the XPath of dv
, you are getting the <h3>
element: 基于
dv
的XPath,您将获得<h3>
元素:
<h3 class="titulo">Mensalidade</h3>
therefore dv.Text
should return "Mensalidade"
. 因此
dv.Text
应该返回"Mensalidade"
。
Try updating your XPath to the <div>
with class='texto'
: 尝试使用
class='texto'
将XPath更新为<div>
:
//div[@class='sa-valor']/div[@class='texto']
试试CssSelector:
var text = driver.FindElement(By.CssSelector("div.texto")).Text;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.