繁体   English   中英

Python Selenium元素在弹出窗口中不可见

[英]Python Selenium element not visible in pop-up window

不知道为什么会收到以下错误。

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible

我尝试为每个游戏(每个没有GT链接的游戏)单击“更多”按钮后,单击“盒子分数”链接。 我是否有问题,因为此按钮显示在弹出式窗口中?

我试图通过使用time.sleep(5)左右来解决这种情况,但是相同的错误会显示在屏幕上,因此,等待链接加载/显示似乎不是问题。

这是我的代码:

schedule = 'http://www.gamecocksonline.com/sports/m-basebl/sched/scar-m-basebl-sched.html'
options = webdriver.ChromeOptions(); options.add_argument("--start-maximized")
driver = webdriver.Chrome(chrome_options=options)
driver.get(schedule)

#Find 'More' button, scroll to, and click
python_button = driver.find_elements_by_xpath("//a[@class='sch-view-more']")[idx]
driver.execute_script("return arguments[0].scrollIntoView();", python_button)
driver.execute_script("window.scrollBy(0, -150);")
python_button.click()

#Click on Box Score link
python_button = driver.find_element_by_xpath("//a[text()='Box Score']")
python_button.click()

#Pass HTML to Beautiful Soup and close browser window
soup = BeautifulSoup(driver.page_source)
playbyplay(soup) #Reads info from the html
driver.quit()

我可以在这里解决自己的问题(感谢@DebanjanB指出了注释中的一些内容)。

添加等待时间以使链接可用,并观察页面顶部的游戏遵循与我搜索的xpath相同的xpath是主要解决方案。

#Click on Box Score link
time.sleep(1)
python_button = driver.find_elements_by_xpath("//span[@class='sch-event-related']")[-1]
python_button.click()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM