ElementNotVisibleException:消息:尝试通过Selenium和Python

我有一个包含源代码的页面,如下面的代码。在我采取行动之后,出现“撤消”和“关闭”按钮。我正在尝试点击“关闭”按钮。我已经尝试了下面的所有三个代码块,没有一个正常工作。有人可以指出我做错了什么,或建议别的尝试吗?


html来源:


<div class="_3Aslx7L3GVI4XM7PUyYKza action-bar"><div class="container"><i class="success-icon fontello-ok-circle"></i><div class="success-message">Your stuff is going to <span>place</span> is on its way.</div><div class="gh69ID1m3_xtdTUQuwadU"><button class="c-button c-button--gray"> Undo</button></div><div class="gh69ID1m3_xtdTUQuwadU"><button class="c-button c-button--blue"> Close</button></div></div></div>

代码尝试:


#driver.find_element_by_id("gh69ID1m3_xtdTUQuwadU").click()

driver.find_element_by_css_selector('.c-button.c-button--blue').click()

#driver.find_element_by_link_text('Close').click()

错误:


---------------------------------------------------------------------------

ElementNotVisibleException                Traceback (most recent call last)

<ipython-input-15-6d570be770d7> in <module>()

      1 #driver.find_element_by_id("gh69ID1m3_xtdTUQuwadU").click()

----> 2 driver.find_element_by_css_selector('.c-button.c-button--blue').click()

      3 #driver.find_element_by_link_text('Close').click()


~/anaconda/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py in click(self)

     78     def click(self):

     79         """Clicks the element."""

---> 80         self._execute(Command.CLICK_ELEMENT)

     81 

     82     def submit(self):


~/anaconda/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py in _execute(self, command, params)

    626             params = {}

    627         params['id'] = self._id

--> 628         return self._parent.execute(command, params)

    629 

    630     def find_element(self, by=By.ID, value=None):

不负相思意
浏览 545回答 3
3回答

精慕HU

WebDriverWait(驱动程序,20).until(EC.element_to_be_clickable((By.CSS_SELECTOR,“div.action-bar button.c-button.c-button - blue”)))。点击()
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python