Home > Net >  Selenium won't keep a drop down open when it clicks it
Selenium won't keep a drop down open when it clicks it

Time:05-14

I am coding python with selenium trying to automate some processes. I have gotten the hang of most of it but I have reached an issue I have seen before. When I use selenium to click a button that opens a drop down menu, it will click the button and open the menu, but only for a millisecond, and the problem is the element in the drop down needs to be visible to be clicked, so the fact that selenium doesn't keep the dropdown open long enough for the next command to trigger (it is a WebDriverWait command to wait until the element is clickable, then to click it. Otherwise it gives an element is not interactable error.).

Does anyone know what I am doing wrong or why selenium won't leave the drop down menu open.

My python code is

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()

and the html code is

<table id="mavthreatdetailcombo-1029-triggerWrap"  cellpadding="0" cellspacing="0" role="presentation" style="table-layout: auto;">
  <tbody role="presentation">
    <tr role="presentation">
      <td id="mavthreatdetailcombo-1029-inputCell"  role="presentation">
      <div  role="presentation" id="ext4-ext-gen1138"></div>
      <input id="mavthreatdetailcombo-1029-inputEl" type="text" role="combobox"  autocomplete="off" value="Show Latest Event" name="mavthreatdetailcombo-1029-inputEl" readonly="readonly" data-errorqtip="" style="width: 159px;">
    </td>
  <td role="presentation" valign="top"  style="width:17px;" id="ext4-ext-gen1137">
    <div  role="presentation" id="ext4-ext-gen1136">
  </div>
</td>
</tr>
</tbody>
</table>

the XPATH I'm using in my code is the XPATH from the html code that follows. It is the code for the down arrow button, that when clicked, will drop down the menu.

<div  role="presentation" id="ext4-ext-gen1136">

CodePudding user response:

Check style classes of the dropdown item, may be dropdown appears by mouse:hover and clicking only behaves to take choosed item .if so , you can change the styles to keep stay appeared .

CodePudding user response:

I figured it out everyone. It looks like it is just some kind of bug, I copied and pasted the code to click the drop down and the second time it clicks it, it stays open, I am not sure why, but if anyone has the same problem where their drop down immediately closes, just try to click it twice.

  • Related