简体   繁体   English

Selenium C#如何将文本形式变量放入XPath

[英]Selenium c# how to put text form variable into xpath

I have problem with putting string from variable into xpath writting test in Selenium c#. 我在将字符串从变量放入Selenium c#中的xpath编写测试时遇到问题。

I am trying to check if url adress from variable is placed in iframe 我正在尝试检查变量中的网址是否放置在iframe中

If I'm trying: 如果我正在尝试:

Assert.True(Page.CheckIfElementIsDisplayOnPage(By.XPath("//div[@class='widget-content']//iframe[contains(@src,'http://www.google.pl')]")));

Everything is ok. 一切都好。 I get info that: 我得到的信息是:

Element "By.XPath: //div[@class='widget-content']//iframe[contains(@src,'http://www.google.pl')]" is displayed.

But if I am trying to put url adress from variable: 但是,如果我尝试从变量中添加网址地址:

string URLAdress = "http://www.google.pl";
Assert.True(Page.CheckIfElementIsDisplayOnPage(By.XPath(String.Format("//div[@class='widget-content']//iframe[contains(@src, {0})]", URLAdress))));

I got the info that: 我得到的信息是:

Element "By.XPath: //div[@class='widget-content']//iframe[contains(@src, http://www.google.pl)] is not displayed

My source code is: 我的源代码是:

<div class="widget-content" style="height: 360.4px;">
<div style="height: 360.4px;">`
<iframe src="http://www.google.pl"/>

Can anybody help me? 有谁能够帮助我? Is it problem that in second condition in information that element is not displayed my url adress is without apostrophe? 在未显示元素的信息的第二种情况下我的网址地址是否没有撇号的问题?

您缺少单引号。

"//div[@class='widget-content']//iframe[contains(@src, '{0}')]"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM