【问题标题】:Selenium ChromeDriver with xpath using contains and lowercaseSelenium ChromeDriver 与 xpath 使用包含和小写
【发布时间】:2018-08-08 14:14:45
【问题描述】:

我是 selenium 和 xpath 的新手,我正在尝试检查 span 是否包含某些文本,同时忽略大小写。我试过引用解决方案 herehere 但没有成功。我有以下内容:

var driver = new ChromeDriver(DRIVER_LOCATION, options);
string name = "doe, john";
// xpath = "(//span[contains(lower-case(text()), lower-case('doe, john'))][contains(@class, 'token-label')])"
string xpath = $"(//span[contains(lower-case(text()), lower-case('{name}'))][contains(@class, 'token-label')])";
var element = driver.FindElement(By.XPath(xpath));

元素中的文本具有“Doe, John”,因此无法找到该元素。在硒的xpath中使用包含时忽略大小写的正确方法是什么?

【问题讨论】:

标签: c# .net selenium xpath


【解决方案1】:

Chrome 不支持小写关键字,您可以使用 translate 关键字,如下所述

"//span//text()[contains(translate(., 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz'),'"+ name + "')]". 

希望这会有所帮助...

【讨论】:

  • 感谢您的澄清。我不知道缺少对小写的 chrome 驱动程序支持。
猜你喜欢
  • 2014-11-02
  • 2020-07-15
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-11-17
  • 1970-01-01
  • 2012-08-15
  • 1970-01-01
相关资源
最近更新 更多