当前位置:网站首页>Foundation 31: Selenium positioning dynamic ID element

Foundation 31: Selenium positioning dynamic ID element

2022-07-25 08:32:00 False face

One . We often encounter elements that need to be located id Not fixed , Unable to get id Positioning

 Insert picture description here

Two . Because of this element id Is dynamic , Unable to get id Property to locate , I had to change to xpath

1. Positioning by absolute path

By.xpath(“/html/body/div[3]/div[2]/div/form/div/div[5]/div/div[3]/div/div[3]/div/div/span/input[9]”)---- Unable to locate

2. Locate by element index

By.xpath(“//input[9]”)— Successful positioning

3. Use xpath Attribute positioning

By.xpath(“//input[@id=‘kw1’]”)

By.xpath(“//input[@type=‘name’ and @name=‘kw1’]”)

4. Use partial property value matching

By.xpath("//input[starts-with(@id,‘file’)

By.xpath("//input[ends-with(@id,‘_11’)

By.xpath(“//input[contains(@id,‘_’)]”)

原网站

版权声明
本文为[False face]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/201/202207191413020891.html