嗨我想知道如果我沒有ID字段時可以使用此命令,它似乎像按鈕接受輸入。我試過.sendKeys,但它似乎沒有做任何事情,地方說不使用.click();命令後。上傳文件沒有ID字段的web驅動程序sendKey
這裏是按鈕的html。
<button class="md-button-icon mt-toolbar-button md-button md-default-theme ng-pristine ng-untouched ng-valid" accept="image/*" ng-model="chatFiles" ng-disabled="!sessionStarted" ng-show="!chatMessage" ng-file-select="" tabindex="0" style="overflow: hidden;" aria-hidden="false" aria-invalid="false" aria-disabled="false">
<mt-icon class="ng-isolate-scope" height="24" width="24" icon=" attachment" style="width: 24px; height: 24px;">
<span>menu</span>
<input type="file" accept="image/*" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;" tabindex="-1" ng-file-generated-elem="true">
</button>
這是我的webdriver代碼:
wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("/html/body/div[2]/div/md-card/md-content/div/div[2]/button[2]")));
WebElement Upload = driver.findElement(By.xpath("/html/body/div[2]/div/md-card/md-content/div/div[2]/button[2]"));
Upload.sendKeys("C:/Users/elsid/Desktop/Eclipse/Workspace/NG - Mentored/Autoit/test.png");
這是從上傳圖片的代碼一路下跌到按鈕一次。
<li class="ng-scope mt-chat-mine" layout="row" ng-class="{ 'mt-chat-mine': message.isMine()}" ng-repeat="message in messages">
<!--
ngIf: !message.isMine()
-->
<!--
ngIf: message.type == 1
-->
<!--
ngIf: message.type == 2
-->
<img class="chat-image ng-scope" ng-if="message.type == 2" ng-src="http://mentoredapp.perrysysdev.com/usercontent/SessionFiles/8040eeaa-3584-4a13-b54e-a16bfadd6433.jpg" src="http://mentoredapp.perrysysdev.com/usercontent/SessionFiles/8040eeaa-3584-4a13-b54e-a16bfadd6433.jpg"></img>
<!--
end ngIf: message.type == 2
-->
<!--
ngIf: message.type == 3
-->
<!--
ngIf: message.isMine()
-->
<img class="avatar ng-scope" ng-if="message.isMine()" ng-src="http://mentoredapp.perrysysdev.com/usercontent/TutorProfilePictures/25f586a2-5031-49a5-94a3-e65305faed8a.png" src="http://mentoredapp.perrysysdev.com/usercontent/TutorProfilePictures/25f586a2-5031-49a5-94a3-e65305faed8a.png"></img>
<!--
end ngIf: message.isMine()
-->
</li>
<!--
end ngRepeat: message in messages
-->
</ul>
<div class="text-box" layout="row">
<textarea id="chat-message-box" class="message-box ng-pristine ng-untouched ng-valid" placeholder="Send a message.." ng-disabled="!sessionStarted" mt-enter="sendChatMessage()" flex="" ng-model="chatMessage" aria-multiline="true" tabindex="0" aria-invalid="false" aria-disabled="false"></textarea>
<button class="md-button-icon mt-toolbar-button md-button md-default-theme ng-hide" ng-transclude="" ng-show="chatMessage" ng-disabled="!chatMessage" ng-click="sendChatMessage()" tabindex="0" aria-hidden="true" aria-disabled="true" disabled="disabled"></button>
<button class="md-button-icon mt-toolbar-button md-button md-default-theme ng-valid ng-dirty ng-valid-parse ng-touched" accept="image/*" ng-model="chatFiles" ng-disabled="!sessionStarted" ng-show="!chatMessage" ng-file-select="" ng-click="clicked" tabindex="0" style="overflow: hidden;" aria-hidden="false" aria-invalid="false" aria-disabled="false">
<mt-icon class="ng-isolate-scope" height="24" width="24" icon=" attachment" style="width: 24px; height: 24px;"></mt-icon>
<span></span>
<input type="file" accept="image/*" style="width: 1px; height: 1px; opacity: 0; position: absolute; padding: 0px; margin: 0px; overflow: hidden;" tabindex="-1" ng-file-generated-elem="true"></input>
</button>
該文件輸入標記是隱藏的嗎? – Saifur
不知道如何檢查?它說隱藏在HTML中,也灰顯 – Elsid