I tried using the Select module, but when I do the Element is either not interactable or it is "not visible". Here are the relevant codes.
HTML
< head > < script > function onChangeCardType() { var value = $('#card_type').val(); $('#img_' + value).siblings().hide(); $('#img_' + value).show(); } </script> </head> <body> <table> <thead> <tr> <th align="left">Card type</th> <td colspan="2" style="font-size:12px;"> <select name="requestDTO.vpc_card" id="card_type" onchange="onChangeCardType()" class="select required" style="width: 342px; font-size:12px;"> <option value="Amex" >American Express</option> <option value="Mastercard" >MasterCard</option> <option value="Visa" >Visa</option> <option value="JCB" >JCB</option> </select> <a class="ui-selectmenu ui-widget ui-state-default select required ui-selectmenu-dropdown ui-corner-all" id="card_type_button_435" role="button" href="#" aria-haspopup="true" aria-owns="card_type_menu_435" aria-expanded="false" tabindex="0" style="width: 336px;"><span class="ui-selectmenu-status">Visa</span><span class="ui-selectmenu-icon ui-icon ui-icon-triangle-1-s"></span></a> <span class="ui-selectmenu-status">Visa</span> <span class="ui-selectmenu-icon ui-icon ui-icon-triangle-1-s"></span> </td> </tr> </thead> </table> </body>
Code
from selenium import webdriver from selenium.webdriver.common.keys import Keys from selenium.webdriver.common.by import By from time import sleep from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import Select #testing on a website that's not public yet, so I won't show the set-up here,but if it's required I can too cardtype = Select(driver.find_element_by_id("card_type")) cardtype.select_by_value("Mastercard") sleep(1) driver.implicitly_wait(2) Using Firefox: ElementNotInteractableException: Element <option> could not be scrolled into view Using Chrome: ElementNotVisibleException: element not visible: Element is not currently visible and may not be manipulated # sleep nor implicitly_wait doesn't help too...
I also tried just clicking on the box (not using the select tag, I could click on it using the class="ui-selectmenu"
, but .send_keys(KEYS.ARROW_DOWN)
doesn't work (gives an AttributeError
).
Is there a way I can identify the text in an option and click on it without using the Select module? Or is there a way I can get the Select module to work in this case?
<a>
tag