首页 > 解决方案 > 无法通过 xpath 定位,因为它的 Xpath 总是在变化

问题描述

我试图通过其内容找到下面的输入元素(也在图片中):在此处输入图像描述

<input _ngcontent-c39="" autocomplete="off" class="remove-input-styling mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-pristine ng-valid ng-touched" matinput="" readonly="true" ng-reflect-owl-date-time="[object Object]" ng-reflect-min="Thu Jun 20 2019 09:38:58 GMT+0" ng-reflect-select-mode="range" ng-reflect-readonly="" ng-reflect-dt-picker="[object Object]" aria-haspopup="true" min="2019-06-20T06:38:58.206Z" id="mat-input-23" aria-invalid="false" aria-required="false">

1.试过了——

self.driver.find_element_by_xpath("//input[contains(.,'remove-input-styling mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-pristine ng-valid ng-touched')]")

  1. 试过了——
WebDriverWait(self.driver, 30).until(EC.presence_of_element_located((By.XPATH, "//input[@class='remove-input-styling mat-input-element mat-form-field-autofill-control cdk-text-field-autofill-monitored ng-untouched ng-pristine ng-valid'][contains(.,' ')]")))

这是执行行:

self.driver.execute_script("arguments[0].click();", self.date_element)

我尝试过的两种方法都没有找到x路径

标签: python-3.xselenium

解决方案


你试过这个 Xpath 吗?

//input[contains(@id,'mat-input')]

推荐阅读