简体   繁体   English

无法与 Python 上的 Selenium 中的元素进行交互

[英]Can't interact with elements in Selenium on Python

I've been trying to search this website ' https://mol.org/regions/?regiontype=countries '.我一直在尝试搜索这个网站 ' https://mol.org/regions/?regiontype=countries '。 But I keep getting the ElementNotInteractableException.但我不断收到 ElementNotInteractableException。 I've tried a lot of methods online but nothing seems to work.我在网上尝试了很多方法,但似乎没有任何效果。 Here is my latest approach:这是我的最新方法:

search_query = 'Egypt'
search_bar_XPath = '//div[@class="region-search"]/div/input[1]'

with webdriver as driver:
    wait = WebDriverWait(driver, 10)
    driver.get(url)
    wait.until(presence_of_element_located((By.CLASS_NAME, 'region-search')))
    search_bar = driver.find_element_by_xpath(search_bar_XPath)
    ActionChains(driver).move_to_element(search_bar).click().perform()
    wait.until(EC.element_to_be_clickable((By.XPATH, search_bar_XPath))).send_keys(search_query + Keys.RETURN)
    
    driver.close()

I can't figure out why the search bar is present but yet not interactable nor accessible.我无法弄清楚为什么搜索栏存在但不可交互或不可访问。

Your issue looks like with browser screen size :您的问题类似于浏览器屏幕尺寸:

try this :试试这个 :

driver.maximize_window()

I tried the below code :我尝试了以下code

driver.maximize_window()
driver.implicitly_wait(30)
driver.get("https://mol.org/regions/?regiontype=countries")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input[placeholder='Filter Political boundaries']"))).send_keys('Egypt')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM