源码如图: 直接使用Select类进行选择,selector(driver.find_element_by_id("Agency")) 会提示如下信息 raise exception_class(message, screen, stacktrace) selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated
# 下拉选择框随机选择 def selector(self,element): ele = Select(element) count_options = len(ele.options) - 1 ele.select_by_index(random.randint(0, count_options))display元素没有定义,直接通过js修改是无效的。必须通过修改元素的style样式的display属性才成功。
agency_ele = driver.find_element_by_id("Agency") js = """ele = document.getElementById("Agency"); ele.style.display='block'; """ driver.execute_script(js) selector(agency_ele)