更新了外部 html 和最新錯誤。似乎檢測到該元素但未能點擊它。
我的腳本在下面的元素失敗,我嘗試了很多方法來重新構建 xpath,但機器人不斷失敗 DOM 無效。
原始元素:
<div class="ant-select SearchPrompter_advInput__3P9Jf ant-select-multiple ant-select-allow-clear ant-select-show-search">
<div class="ant-select-selector">
<div class="ant-select-selection-overflow">
<div class="ant-select-selection-overflow-item ant-select-selection-overflow-item-suffix" style="opacity: 1;">
<div class="ant-select-selection-search" style="width: 3px;">
<input autocomplete="off" type="search" class="ant-select-selection-search-input" role="combobox" aria-haspopup="listbox" aria-owns="rc_select_2_list" aria-autocomplete="list" aria-controls="rc_select_2_list" aria-activedescendant="rc_select_2_list_0" value="" id="rc_select_2" style="opacity: 0;" aria-expanded="false" readonly="" unselectable="on">
<span class="ant-select-selection-search-mirror" aria-hidden="true"> </span>
</div>
</div>
</div>
<span class="ant-select-selection-placeholder">Select Source(s)</span>
</div>
</div>
腳本:
*** Settings ***
Library Browser
Library OperatingSystem
Resource ../Resources/BrowserParameters.robot
Resource ../Resources/BrowserResources.robot
Resource ../Resources/BrowserCustomKeywords.robot
#Select Browser: chromium or firefox
Test Setup Test Setup Browser=chromium
Test Teardown Test Teardown
*** Test Cases ***
001
Click //span[contains(@class,'ant-select-selection-placeholder') and contains(text(),'Select Source(s)')]
錯誤
FAIL
Message: TimeoutError: locator.click: Timeout 10000ms exceeded.
=========================== logs ===========================
waiting for selector "//span[contains(@class,'ant-select-selection-placeholder') and contains(text(),'Select Source(s)')] >> nth=0"
selector resolved to hidden <span class="ant-select-selection-placeholder">Select Source(s)</span>
attempting click action
waiting for element to be visible, enabled and stable
element is not stable - waiting...
element is visible, enabled and stable
scrolling into view if needed
done scrolling
checking that element receives pointer events at (1080.4,304.7)
<div class="ant-select-selection-overflow">…</div> intercepts pointer events
retrying click action, attempt #1
waiting for element to be visible, enabled and stable
element is visible, enabled and stable
scrolling into view if needed
done scrolling
checking that element receives pointer events at (1080.4,304.7)
[ Message content over the limit has been removed. ]
element is visible, enabled and stable
scrolling into view if needed
done scrolling
checking that element receives pointer events at (1080.4,304.7)
<div class="ant-select-selection-overflow">…</div> intercepts pointer events
如果我使用它,那么我可以看到正在訪問的欄位并顯示串列。但是在表單中有 2 個欄位使用相同的 xpath。所以機器人進入了第一個領域,但我希望它進入下一個領域。
Click //div[@]
uj5u.com熱心網友回復:
請更正您的 Xpath
//span[@ant-select-selection-placeholder">Select Source(s)"]
到
//span[@]
或者
//span[@ and (text()="Select Source(s)")]
uj5u.com熱心網友回復:
這個錯誤資訊...
Error: locator.click: DOMException: Failed to execute 'evaluate' on 'Document': The string './/span[@ant-select-selection-placeholder">Select Source(s)"]' is not a valid XPath expression.
...暗示您使用的XPath無效路徑 表達。
您必須進行以下兩個小調整:
- class 屬性的值必須在單雙引號內,即
"value" Select Source(s)是內部的 innerText ,因此您必須將其稱為text。
解決方案
您可以使用以下任一定位器策略:
路徑 1:
//span[@class='ant-select-selection-placeholder' and starts-with(., 'Select Source')]路徑 2:
//span[@class='ant-select-selection-placeholder' and contains(., 'Select Source')]
uj5u.com熱心網友回復:
請使用下面的xpath
//span[contains(@class,'ant-select-selection-placeholder') and contains(text(),'Select Source(s)')]
或者
//span[contains(@class,'ant-select-selection-placeholder') and starts-with(text(),'Select Source')]
請檢查dev tools(谷歌瀏覽器)我們是否有唯一的條目HTML DOM。
檢查步驟:
Press F12 in Chrome- >去element節- >做一個CTRL F- >再貼上xpath看看,如果你需要的element是越來越強調與1/1匹配的節點。
如果我們有 1/1 匹配節點,請確保:
- 此 div 不在 iframe 下。
- 這個 div 不在 shadow-root 下。
- 您不應該在 selenium 啟動的新選項卡/視窗上。
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/355522.html
