用python+selenium登录上海电机学院官网并选课出现的问题


问题1:页面跳转后再查找东西时报NoSuchElementException: Message: Unable to locate element
原因:handle发生了变化
解决方法:driver.switch_to_window(driver.currenHandle)
问题2:怎么查找下拉菜单的元素
解决方法:webdriver.ActionChains(driver).move_to_element(xuanke).perform(),使用ActionChains类
问题3:查找下拉列表时,handle没变化,查找元素时,报错元素不可见
原因:页面还没加载出来你就查找,肯定找不到
解决方法:WebDriverWait(driver,10).until(lambda driver:driver.find_element_by_xpath("//*[@id='nav']/li[5]/ul/li[1]/a").is_displayed()),每10 秒刷新一下,让它加载完毕

原文地址:https://www.cnblogs.com/wantao/p/8336584.html