gpt4 book ai didi

xpath 选择器中的 C# 变量

转载 作者:太空宇宙 更新时间:2023-11-03 17:43:46 25 4
gpt4 key购买 nike

我可以将 C# 字符串变量传递给 xpath 选择器吗?这是用于 Selenium 单元测试。我想做这样的事情:

string myText = "foo";    
Assert.IsTrue(Browser.IsElementPresent("//option[contains(text(), $myText)]"));

最佳答案

使用 string.Format 应该有效:

Assert.IsTrue(Browser.IsElementPresent(string.Format("//option[contains(text(), {0}]",myText)));

关于xpath 选择器中的 C# 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10500557/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com