【发布时间】:2018-04-12 23:48:24
【问题描述】:
目标是单击登录页面上的复选框。 我通过 XPATH 找到了该元素,但无法点击它。
>>> elem = driver.find_element_by_xpath("//input[@type='checkbox'][@name='conditions']")
>>> elem.is_displayed()
False
>>> elem.is_enabled()
True
>>> elem.get_attribute('outerHTML')
u'<input type="checkbox" class="custom-control-input" name="conditions">'
当我尝试elem.click() 时,出现异常:
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible 但元素清晰可见,因为页面已加载并且我从终端工作。
当我使用不同的选择器时的其他错误是:
driver.find_element_by_xpath('/html/body/div[2]/main/section/div/div[3]/div/div[1]/form/p[1]/label/input').click()
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <input type="checkbox" class="custom-control-input" name="conditions"> is not clickable at point (51, 549). Other element would receive the click: <span class="custom-control-description font-weight-regular">...</span>
我尝试注入 JavaScript,但没有成功。
driver.execute_script("arguments[0].style.visibility = 'visible';",elem)
任何想法如何解决这个问题?
【问题讨论】:
-
尝试显式等待元素的可见性然后点击它。
标签: javascript python selenium checkbox webdriver