如何在Selenium IDE中使用Regex获取ID?

时间:2017-10-27 14:20:38

标签: selenium selenium-ide

我有一个像:6g.custom-0这样的可更改ID。此更改始终与:7a.custom-0一样。

我将此用于Gmail以更改Selenium IDE中的主题。

我喜欢这些是:

  1. id=regex:(.{4}custom-[0-9]{1})
  2. css=[id$=.custom-0];
  3. 但这些都没有用......

    所以请帮帮我......

2 个答案:

答案 0 :(得分:0)

  

我有一个可更改的ID

xpath' contains功能解决了这个问题。我在这台机器上没有Firefox IDE,因此我使用kantu selenium ide为chrome记录了主题更改,然后删除了ID的更改部分:contains(@id, 'custom-3') =>效果很好。下面的测试找到并点击两个主题。

{
  "CreationDate": "2017-10-28",
  "Commands": [
    {
      "Command": "click",
      "Target": "//*[contains(@id, 'custom-3')]/div[2]",
      "Value": ""
    },
    {
      "Command": "click",
      "Target": "//*[contains(@id, 'custom-2')]/div[2]",
      "Value": ""
    }
  ]
}

答案 1 :(得分:-1)

令人惊讶的是人们如何花时间写下他们的问题,但却没有时间去搜索谷歌。

看来你可能不得不使用正则表达式:

enter image description here

请点击链接:

https://seleniumonlinetrainingexpert.wordpress.com/2012/11/29/how-to-use-regular-expression-in-selenium-ide/