硒能否将aria-uuid识别为对象识别的ID? [英] Can selenium recognize aria-uuid as an ID for object recognition?
问题描述
我最近向我的开发人员建议将ID添加到我正在努力使自动化更稳定的项目的每个元素上,他们在aria-uuid中添加了每个元素.我什么也无法识别这些ID!我想知道是否有可能?
I recently recommended to my devs to add IDs to each element on the project I'm working to make automation more robust, they added in aria-uuid to each element. I cannot get anything to recognize these IDs! I'm wondering if it is even possible?
我正在使用python/硒.
I'm using python/selenium.
我尝试过通过ID标识元素,已经完成了CSS选择器和xpath,但是它们之间有在新版本之间进行中断的历史.
I've tried identifying elements by ID, I've done CSS selectors and xpaths but they have had a history of breaking between new builds.
相关html:
input class="short ng-valid ng-not-empty ng-valid-min ng-valid-required" name="question_16" type="number" aria-uuid="question_16_input" ng-required="true" ng-min="0" ng-model="$ctrl.vault['question_16'].value"
def click_element_by_id(self, driver_init, id1, message1, delay1, halt):
try:
element = WebDriverWait(driver_init, delay1).until(EC.element_to_be_clickable((By.ID, id1)))
element.click()
except TimeoutException:
if halt:
assert_that(True, message1).is_false()
else:
print(message1)
每次出现断言/超时错误
Each time I get the assertion/timeout error
推荐答案
理想情况下,是,您应该已经能够识别每个元素的 aria-uuid
与 Selenium ,前提是所生成的 aria-uuid
是静态.
Ideally, yes you should have been able to recognize each individual elements with respect to their aria-uuid
to be used with Selenium provided the generated aria-uuid
were static.
根据您所共享的HTML,所生成的 aria-uuid
似乎是动态的.因此,仅 aria-uuid
不会帮您.在这些情况下,您必须使用 aria-uuid
以及其他 attributes
来唯一标识元素.要标识此元素,您可以使用以下定位器策略:
As per the HTML you have shared the generated aria-uuid
seems to be dynamic. So aria-uuid
alone won't help you. In these cases you have to use the aria-uuid
along with the other attributes
to uniquely identify the elements. To identify this element you can use either of the following Locator Strategies:
-
使用
CSS_SELECTOR
:
WebDriverWait(driver_init, delay1).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.short.ng-valid.ng-not-empty.ng-valid-min.ng-valid-required[aria-uuid$='_input'][name^='question_']"))).click()
使用 XPATH
:
WebDriverWait(driver_init, delay1).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='short ng-valid ng-not-empty ng-valid-min ng-valid-required' and contains(@aria-uuid, '_input')][starts-with(@name, 'question_')]"))).click()
这篇关于硒能否将aria-uuid识别为对象识别的ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!