在将它用于 xpath 大小写不敏感时对 translate() 函数感到困惑

Confusion about translate() function while using it for xpath case insensitivity

我正在使用 selenium 和 java 自动化页面,并尝试在翻译功能的帮助下使用不区分大小写的 xpath,如下所示。

driver.findElement(By.xpath("//a[contains(translate(.,'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdefghijklmnopqrstuvwxyz'),'tools')]")).click();

'tools' 页面上的文本为 'Tools'。 [T 为大写]

现在我的问题是,

有人帮帮我。

image 1 image 2

Now my question is,

  • What does '.,' means in the above code?
  • Using 'tools' in place of '.,' gives all the //a links. Reason?
  • Whenever I use 'Tools' instead of 'tools' in the above code, it does not work.

点步是一种缩写语法,来自specs:

. selects the context node

因为它被用作需要字符串的函数的参数,所以将通过 string() 函数进行转换。

字符串 'tools' 始终包含字符串 'tools',因此当您使用 . 时,您不会过滤任何 selected a 元素

另一方面,任何小写字符串都不会包含字符串 'Tools',因此您将无法 select 任何内容。