我无法找到此框的元素以单击以弹出日期选择器
任何帮助将不胜感激
当我检查元素时,这就是我看到的... Xpath也不起作用
<input ng-disabled="viewOnly" class="formInput effectiveDates ng-pristine ng-isolate-scope hasDatepicker ng-empty ng-invalid ng-invalid-required ng-not-modified ng-touched" autocomplete="off" name="effectiveStartDate" ng-required="true" placeholder="Select/Enter date(mm/dd/yyyy)" type="search" ng-model="authObj.authStartDate" value="" ng-keydown="preventUserEnterDateInfo($event)" datepicker="" minimumdate="02/27/2020" ng-change="effectiveDateChange(authObj.authStartDate)" ng-class="(authListForm.$submitted && authListForm.effectiveStartDate.$invalid)?'reqd':''" id="dp1582663746532" required="required">
所需元素是Angular元素,因此要在元素上定位/ click()
,需要为elementToBeClickable()
引入WebDriverWait,并且可以使用以下Locator Strategies中的任何一个:
cssSelector
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("input.formInput.effectiveDates.ng-pristine.ng-isolate-scope.hasDatepicker.ng-empty.ng-invalid.ng-invalid-required.ng-not-modified.ng-touched[name='effectiveStartDate'][placeholder*='Enter date']"))).click();
xpath
:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@class='formInput effectiveDates ng-pristine ng-isolate-scope hasDatepicker ng-empty ng-invalid ng-invalid-required ng-not-modified ng-touched' and @name='effectiveStartDate'][contains(@placeholder, 'Enter date')]"))).click();
您可以尝试使用JavascriptExecutor单击。
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
或者您可以尝试使用坐标单击:
Actions builder = new Actions(driver);
builder.moveToElement(element, 10, 25).click().build().perform();