首页 > 解决方案 > 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.

标签: pythonselenium-webdriver

解决方案


在下面查找如何定位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]')

推荐阅读