GVKun编程网logo

ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素

21

想了解ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于

想了解ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素的新动态吗?本文将为您提供详细的信息,此外,我们还将为您介绍关于ElementClickInterceptedException:消息:元素点击被拦截其他元素会收到点击:Selenium Python、ElementNotVisibleException:Selenium Python、ElementNotVisibleException:消息:尝试通过Selenium和Python单击按钮时,元素不可交互错误、OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找的新知识。

本文目录一览:

ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素

ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素

我试图单击“所有主题”和“所有状态”复选框,然后搜索结果。当我运行脚本时,会打开一个Chrome窗口,大小为1036x674。

如果我不理会窗口,则会出现元素点击拦截错误。如果我最小化或最大化窗口,则脚本可以正常工作。

我正在使用Selenium 3.141.0,chrome 76,chromedriver 76和python 3.6

chromedriver_path = r"C:\Users\path\to\chromedriver.exe"browser = webdriver.Chrome(executable_path=chromedriver_path)url = "http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx"topics_xpath = "//*[@id=\"dnn_ctr81355_StateNetDB_UpdatePanel1\"]/div[1]/div[2]/span/label"states_xpath = "//*[@id=\"dnn_ctr81355_StateNetDB_UpdatePanel1\"]/div[2]/div[2]/span/label"browser.get(url)time.sleep(30)elem = browser.find_element_by_xpath(topics_xpath)elem.click()time.sleep(5)elem = browser.find_element_by_xpath(states_xpath)elem.click()

但是我得到这个错误:

ElementClickInterceptedException:消息:拦截了元素单击:
元素

将要单击的CheckBox在我要单击的复选框的正下方。

答案1

小编典典

您需要WebDriverWait确定元素visibility_of_element_located,然后滚动到SearchableDatabasesection,然后可以使用locator xpath

请输入:

from selenium.webdriver.support import expected_conditionsfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWait

尝试下面的代码。

chromedriver_path = r"C:\Users\path\to\chromedriver.exe"browser = webdriver.Chrome(executable_path=chromedriver_path)url = "http://www.ncsl.org/research/transportation/autonomous-vehicles-legislative-database.aspx"topics_xpath = "//div[@divTopicsSection1'']//span//label[text()=''All Topics'']"states_xpath = "//div[@divStatesSection1'']//span//label[text()=''All States'']"dBase_xpath = "//h4[text()=''Searchable Database'']"browser.get(url)WebDriverWait(browser, 10).until(expected_conditions.visibility_of_element_located((By.XPATH, topics_xpath)))elem = browser.find_element_by_xpath(dBase_xpath)browser.execute_script("arguments[0].scrollIntoView(true);", elem)browser.find_element_by_xpath(topics_xpath).click()browser.find_element_by_xpath(states_xpath).click()

ElementClickInterceptedException:消息:元素点击被拦截其他元素会收到点击:Selenium Python

ElementClickInterceptedException:消息:元素点击被拦截其他元素会收到点击:Selenium Python

如何解决ElementClickInterceptedException:消息:元素点击被拦截其他元素会收到点击:Selenium Python?

我已经看到有关此错误的其他问题,但我的情况是在我的程序中,另一个元素应该收到点击。详细说明:webdriver 正在滚动谷歌搜索,它必须点击它找到的每个网站,但程序阻止了它。我怎样才能让它不搜索它点击的上一个网站?

这就是功能。程序正在循环它,在第一个循环之后它向下滚动并出现错误:

def get_info():
browser.switch_to.window(browser.window_handles[2])
description = webdriverwait(browser,10).until(
    EC.presence_of_element_located((By.TAG_NAME,"h3"))
).text

site = webdriverwait(browser,"cite"))
)
site.click()

url=browser.current_url
#removes the https:// and the / of the url
#to get just the domain of the website
try:
    link=url.split("https://")
    link1=link[1].split("/")
    link2=link1[0]
    link3=link2.split("www.")
    real_link=link3[1]

except IndexError:
    link=url.split("https://")
    link1=link[1].split("/")
    real_link=link1[0]

time.sleep(3)
screenshot=browser.save_screenshot("photos/"+"(" + real_link + ")" + ".png")
global content
content=[]
content.append(real_link)
content.append(description)
print(content)
browser.back()
time.sleep(5)
browser.execute_script("window.scrollBy(0,400)","")
time.sleep(5)

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

ElementNotVisibleException:Selenium Python

ElementNotVisibleException:Selenium Python

如何解决ElementNotVisibleException:Selenium Python?

关于解决方案的几句话:

  1. 与预期子句的条件presence_of_element_located()涉及 用于检查的元件是存在于页面的DOM的期望。 这并不一定意味着该元素是可见的。一旦找到元素,用于查找元素的定位器将返回WebElement。因此,我们必须更改与 期望 相关的子句,presence_of_element_located()检查用于检查已知在页面DOM中存在的元素是否可见。 可见性意味着不仅显示元素,而且其高度和宽度都大于0。element是WebElement在可见时返回(相同)WebElement 。 __
  2. 展望未来,您已经尝试click()WebElement 调用方法。因此,代替presence_of_element_located()我们将使用该 子句。
  3. 这是您自己的代码,做了一些小的更改:
        try:
        element = wait.until(EC.element_to_be_clickable((By.XPATH, "//*[@id=''_ariaId_73.folder''] | //*[@id=''_ariaId_133.folder'']")))
    except: 
        print "403 : Monitoring Not Found"
    element.click()

解决方法

我已经检查了所有以前的类似问题,它们不适用于我的情况。

       try:
          element = wait.until(
          EC.presence_of_element_located((By.XPATH,"//*[@id=''_ariaId_73.folder''] | //*[@id=''_ariaId_133.folder'']"))
       )
       except: 
          print "403 : Monitoring Not Found"

    element.click()

它是不会进入异常块还可以,但它仍然抛出ElementNotVisibleExceptionelement.click()方法。

ElementNotVisibleException:消息:尝试通过Selenium和Python单击按钮时,元素不可交互错误

ElementNotVisibleException:消息:尝试通过Selenium和Python单击按钮时,元素不可交互错误

如何解决ElementNotVisibleException:消息:尝试通过Selenium和Python单击按钮时,元素不可交互错误?

与文本的元素 是一个动态的元素,以便找到你要引起元素 webdriverwait元素是可点击 ,你既可以使用以下方法解决:

  • 使用CSS_SELECTOR

    webdriverwait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "div.action-bar button.c-button.c-button--blue"))).click()
    
  • 使用XPATH

    webdriverwait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[contains(@class, ''action-bar'')]//button[@c-button c-button--blue'' and normalize-space()=''Close'']"))).click()
    
  • :您必须添加以下导入:

        from selenium.webdriver.support.ui import webdriverwait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC

解决方法

我有一个包含源代码的页面,如下面的代码。在执行操作后,在其中显示“撤消”和“关闭”按钮。我试图单击“关闭”按钮。我已经尝试了下面的所有三个代码块,但都无法正常工作。有人可以指出我做错了什么,还是建议其他尝试?

html来源:

<div><div><i></i><div>Your stuff is going to <span>place</span> is on its way.</div><div><button> Undo</button></div><div><button> 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):

~/anaconda/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py in execute(self,driver_command,params)
    318         response = self.command_executor.execute(driver_command,params)
    319         if response:
--> 320             self.error_handler.check_response(response)
    321             response[''value''] = self._unwrap_value(
    322                 response.get(''value'',None))

~/anaconda/envs/py36/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py in check_response(self,response)
    240                 alert_text = value[''alert''].get(''text'')
    241             raise exception_class(message,screen,stacktrace,alert_text)
--> 242         raise exception_class(message,stacktrace)
    243 
    244     def _value_or_default(self,obj,key,default):

ElementNotVisibleException: Message: element not interactable
  (Session info: chrome=72.0.3626.109)
  (Driver info: chromedriver=2.42.591059 (a3d9684d10d61aa0c45f6723b327283be1ebaad8),platform=Mac OS X 10.12.6 x86_64)

OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找

OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找

如何解决OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找?

Message: 
Test method CFSSOnlineBanking.SmokeTests.Transferdisplay threw exception: 
OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#menuLeftRailContainer > div:nth-child(1) > div:nth-child(3)"}
  (Session info: chrome=91.0.4472.164)

Stack Trace: 
RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
RemoteWebDriver.Execute(String driverCommandToExecute,Dictionary`2 parameters)
RemoteWebDriver.FindElement(String mechanism,String value)
RemoteWebDriver.FindElementByCssSelector(String cssSelector)
<>c__displayClass23_0.<CssSelector>b__0(ISearchContext context)
By.FindElement(ISearchContext context)
RemoteWebDriver.FindElement(By by)
TransferPage.get_TransferLink() line 22
SmokeTests.Transferdisplay() line 57

我目前正在尝试单击位于 div 内的 href。无论我尝试什么,似乎都无法点击它。

enter image description here

这是我检查时的元素。

enter image description here

我尝试添加等待 我尝试通过 LinkText、PartialLinkText、cssSelector 和 xPATH 单击

目前我在 TransferPage 类中有这个:

public IWebElement TransferLink => _driver.FindElement(By.CssSelector("#menuLeftRailContainer > div:nth-child(1) > div:nth-child(3)"));

然后在我的实际测试方法中:

_driver.Manage().Timeouts().ImplicitWait = TimeSpan.FromSeconds(15);
transferPage.TransferLink.Click();

解决方法

您可以尝试以下方法吗

xpath :

//a[@href=''/connect-native/transfer/'']

或 css 选择器

a[href=''/connect-native/transfer/''] 

在代码中:

public IWebElement TransferLink => _driver.FindElement(By.CssSelector("a[href=''/connect-native/transfer/'']"));

因为您在代码中使用的 css 选择器看起来有点乱。你确定有 1/1 匹配的元素吗?

如果这不起作用,您能在您的网页中查找 iframe 吗?

今天关于ElementClickInterceptedException:消息:拦截了元素单击:Selenium和Python无法单击元素的分享就到这里,希望大家有所收获,若想了解更多关于ElementClickInterceptedException:消息:元素点击被拦截其他元素会收到点击:Selenium Python、ElementNotVisibleException:Selenium Python、ElementNotVisibleException:消息:尝试通过Selenium和Python单击按钮时,元素不可交互错误、OpenQA.Selenium.NoSuchElementException:没有这样的元素:无法定位元素 C# 按类查找等相关知识,可以在本站进行查询。

本文标签: