关于webdriver定位元素,报错无法点击
程序员文章站
2022-03-24 08:41:00
...
1.换ENTER键
from selenium.webdriver.common.keys import Keys
imageTypeRadio = '//i[starts-with(@class,"input-helper") and contains(.,"%s")]'% image_type
context.driver.find_element_by_xpath(imageTypeRadio).send_keys(Keys.ENTER)
2.元素在页面下方,被遮挡,聚焦到元素后再点击
ERROR Message: unknown error: Element <label>...</label> is not clickable at point (597, 835). Other element would receive the click: <div data-v-d25eeca0="" class="button-box" style="top: 777px;">...</div>
解决方法:聚焦滚动到元素可见,再点击
3.元素被透明遮罩层遮挡,等待遮罩层消失
ERROR Message: unknown error: Element <button class="k-btn" tabindex="0" type="button">...</button> is not clickable at point (811, 352). Other element would receive the click: <div class="ksc-loading-mask"></div>
解决方法:
from selenium.webdriver.common.keys import Keys
imageTypeRadio = '//i[starts-with(@class,"input-helper") and contains(.,"%s")]'% image_type
context.driver.find_element_by_xpath(imageTypeRadio).send_keys(Keys.ENTER)
2.元素在页面下方,被遮挡,聚焦到元素后再点击
ERROR Message: unknown error: Element <label>...</label> is not clickable at point (597, 835). Other element would receive the click: <div data-v-d25eeca0="" class="button-box" style="top: 777px;">...</div>
解决方法:聚焦滚动到元素可见,再点击
target = driver.find_element_by_id("id_keypair") driver.execute_script("arguments[0].scrollIntoView();", target) #拖动到可见的元素去
3.元素被透明遮罩层遮挡,等待遮罩层消失
ERROR Message: unknown error: Element <button class="k-btn" tabindex="0" type="button">...</button> is not clickable at point (811, 352). Other element would receive the click: <div class="ksc-loading-mask"></div>
解决方法:
from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.common.by import By def wait_loading(context): try: WebDriverWait(context.driver, 1, 0.1).until( EC.visibility_of_element_located((By.XPATH, "//div[@class='ksc-loading-mask']"))) except TimeoutException: pass WebDriverWait(context.driver, SMALL_TIME_OUT).until( EC.invisibility_of_element_located((By.XPATH, "//div[@class='ksc-loading-mask']")))
上一篇: Tomcat 7 RC4 发布
下一篇: 甲骨文推出移动应用设计模式