Python+Selenium 下拉列表报错Message: element not interactable

  今天准备作一个购车页面的自动化,写到下拉列表时,运行脚本抛出了异常:selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable前端

  以下图所示,一开始使用了select_by_index()的方法,脚本运行失败,发现是没仔细查看代码~~,此处代码不是select-option,而是table。调试

  脚本以下:blog

driver.find_element_by_xpath("//*[@id=\"style_box\"]/div[1]").click()
#Select(s).select_by_index(3)
driver.find_element_by_xpath("//*[@id=\"style_box\"]/div[2]/div[1]/table/tbody/tr[2]").click()

  很简单的两个点击,运行以后报错selenium.common.exceptions.ElementNotVisibleException: Message: element not interactableelement

  调试了几回,发现是没有加等待时间的缘故,加了time.sleep(3),再次调试,成功了。selenium

  总结了一下,一方面必定要分析前端代码,另外一方面当脚本报错时,尤为涉及到切换的时候,不如加个等待时间试一下吧~~自动化