'Selenium won't keep a drop down open when it clicks it
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" 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>
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 class="x4-trigger-index-0 x4-form-trigger x4-form-arrow-trigger x4-form-trigger-first" role="presentation" id="ext4-ext-gen1136">
Solution 1:[1]
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.
Solution 2:[2]
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 .
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | DDUffy |
Solution 2 | Meelad Ghazipour |