簡體   English   中英

Selenium 在單擊時不會保持打開狀態

[英]Selenium won't keep a drop down open when it clicks it

我正在用 selenium 編碼 python 試圖自動化一些過程。 我已經掌握了大部分內容,但我遇到了一個我以前見過的問題。 當我使用selenium單擊打開下拉菜單的按鈕時,它會單擊按鈕並打開菜單,但只有一毫秒,問題是下拉菜單中的元素需要可見才能被單擊,所以selenium 沒有使下拉菜單保持足夠長的時間以觸發下一個命令(這是一個 WebDriverWait 命令,等待元素可單擊,然后單擊它。否則它會給出一個元素不可交互錯誤。)。

有誰知道我做錯了什么或者為什么硒不會打開下拉菜單。

我的python代碼是

browser.find_element(by=By.XPATH, value='//*[@id="ext4-ext-gen1136"]').click()

WebDriverWait(browser, 20).until(EC.element_to_be_clickable((By.XPATH, "//ul[@class='x4-list-plain']//li[@class='x4-boundlist-item' and text()='Show All Events and Traces']"))).click()

並且html代碼是

<table id="mavthreatdetailcombo-1029-triggerWrap" class="x4-form-trigger-wrap" cellpadding="0" cellspacing="0" role="presentation" style="table-layout: auto;">
  <tbody role="presentation">
    <tr role="presentation">
      <td id="mavthreatdetailcombo-1029-inputCell" class="x4-form-trigger-input-cell" role="presentation">
      <div class="x4-hide-display x4-form-data-hidden" role="presentation" id="ext4-ext-gen1138"></div>
      <input id="mavthreatdetailcombo-1029-inputEl" type="text" role="combobox" class="x4-form-field x4-form-text x4-trigger-noedit x4-form-focus x4-field-form-focus x4-field-default-form-focus" autocomplete="off" value="Show Latest Event" name="mavthreatdetailcombo-1029-inputEl" readonly="readonly" data-errorqtip="" style="width: 159px;">
    </td>
  <td role="presentation" valign="top" class=" x4-trigger-cell x4-unselectable" style="width:17px;" id="ext4-ext-gen1137">
    <div class="x4-trigger-index-0 x4-form-trigger x4-form-arrow-trigger x4-form-trigger-first" role="presentation" id="ext4-ext-gen1136">
  </div>
</td>
</tr>
</tbody>
</table>

我在代碼中使用的 XPATH 是來自后面的 html 代碼的 XPATH。 這是向下箭頭按鈕的代碼,單擊該按鈕時將下拉菜單。

<div class="x4-trigger-index-0 x4-form-trigger x4-form-arrow-trigger x4-form-trigger-first" role="presentation" id="ext4-ext-gen1136">

檢查下拉項目的樣式類,可能是通過鼠標出現的下拉菜單:懸停並單擊僅行為以獲取所選項目。如果是這樣,您可以更改樣式以保持出現。

我想通了大家。 看起來它只是某種錯誤,我復制並粘貼了代碼以單擊下拉菜單,第二次單擊它時,它保持打開狀態,我不知道為什么,但是如果有人在他們的下拉菜單中遇到同樣的問題down 立即關閉,只需嘗試單擊它兩次。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM