[Python] [Selenium]“。find_element_by_class_name.click()”上的错误

下面写的是我的Python Selenium测试代码。它在google.com上搜索“迪拜到新加坡”。效果很好。

但是,当我将代码修改为以下两种方式时,遇到了以下错误:

---------------------------------------------------------------------------------------------
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=78.0.3904.97)
---------------------------------------------------------------------------------------------
  1. 删除第8和9行

    我删除了这些行,因为我认为这些不是必需的。

    除此之外,代码上没有任何变化。

  2. 搜索“步行从迪拜到新加坡”

    我刚刚在搜索关键字的末尾添加了“步行”。

    除此之外,代码上没有任何变化。

from selenium import webdriver
from selenium.webdriver.common.by import By

driver = webdriver.Chrome()
driver.get("https://www.google.com/en")

driver.find_element_by_name("q").send_keys("Dubai to singapore")
print(driver.find_element_by_name("btnK").get_attribute("value")) #print: Google Search
print(driver.find_element_by_name("btnI").get_attribute("value")) #print: I'm feeling lucky
search_button = driver.find_element_by_name("btnK")
search_button.click()
sarah928 回答:[Python] [Selenium]“。find_element_by_class_name.click()”上的错误

您的问题可以使用PyAutoGUI解决(请务必先安装)

extension SlidingCardView: UICollectionViewDelegate {

  func collectionView(_ collectionView: UICollectionView,willDisplay cell: UICollectionViewCell,forItemAt indexPath: IndexPath) {
    // THIS IS FIRED BUT UISCROLLVIEW METHODS NOT
  }

  func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
    print(111)
  }


  func scrollViewWillBeginDragging(_ scrollView: UIScrollView) {
    print("1111111")
  }
}
,

发生此问题的原因是search_button = driver.find_element_by_name("btnK")由于该列表而被隐藏。如果要解决此问题,请参考以下代码。

enter image description here

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Chrome(executable_path=r"C:\chromedriver.exe")

driver.set_page_load_timeout("10")
driver.get("http://google.com")
element=driver.find_element_by_name("q")
element.send_keys("Dubai to singapore")
element.send_keys(Keys.RETURN);
本文链接:https://www.f2er.com/3129125.html

大家都在问