Handle elements that have changing ids all the time through Selenium Webdriver

前端 未结 3 966
小鲜肉
小鲜肉 2020-12-20 07:36

I am running the script to automate test cases and having this unique problem. I have detected and used IDs of the elements for click etc. purpose. However, all of a sudden

3条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-20 07:59

    You can utilize CSS for this. For your element, looks like its:

    <* id="tile276_input" />
    

    What you need to do is find out what is changing about it. I assume it's the number inbetween. If it is, then your selector would look something like:

    By.cssSelector("*[id^='tile'][id$='input']")
    

    This will look for anything that has an ID that "starts with tile" and "ends with input. In our case, "tile276_input" matches that.

    See this article if you want more information

提交回复
热议问题