python - selenium error ElementNotVisibleException: element not visible
问题描述
i am trying to click on element in chrome driver browser using python and selenium. when trying to click i get the element not visible exception. this is html code:
<div class="mid-content"><ul><li><b><span>Private</span><span><!-- react-text: 715 --> (<!-- /react-text --><!-- react-text: 716 -->
3<!-- /react-text --><!-- react-text: 717 -->)
<!-- /react-text --></span></b></li><li><img alt="" src="../img/UserProfile/lock.svg" width="18" height="24"></li><li class="bottom-title">Request to View</li></ul></div>
this is how click by xpath:
browser.find_element_by_xpath('//*[@id="App-content"]/div/div[1]/div[2]/div[1]/div[3]/div/div/a/div/ul')
its not working. but if i click in chrome driver browser manually first and then run this line of code it's everything working fine. What's the trick?please help me to solve this problem.
解决方案
在下面查找如何定位ul元素的不同示例。
通过 css 选择器获取ul元素:
browser.find_element_css_selector('#App-content .mid-content ul')
获取包含“Private”和“3”文本的ul元素:
browser.find_element_by_xpath('//*[@id="App-content"]//ul[contains(.,"Private") and contains(.,"3")]')
获取包含带有“请求查看”文本的li并具有子img标记的ul元素:
browser.find_element_by_xpath('//*[@id="App-content"]//ul[./li[.="Request to View"] and .//img]')
推荐阅读
- nginx - 使用 nginx 到不同主机的不同前缀路径
- excel - 使用 VBA 绕过网站的安全证书警告
- android - 迁移到 androidX 后,Retrofit 界面中的 Kapt NonExistentClass 异常
- javascript - fancybox 两个图像显示在同一个窗口
- python - 带有“+”选项的 argparse
- javascript - 用另一个 HTML 标记将 HTML 标记包装在纯字符串中
- javascript - React Native 未处理的异常未在 ErrorUtils 中捕获 & 发布 APK 显示空白屏幕而不是在 JS 异常上崩溃
- android - 在 Android Kotlin 中,assertNotNull 导致单元测试无法运行
- javascript - 使用不同的数据属性使多个计数器计数
- javascript - 如何在类方法中处理 redux 道具