我的代码是这个,它是从下拉菜单中选择的,但是在“ ilseçiniz”中
我遇到错误selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable: Element is not currently visible and may not be manipulated
为什么无法从此菜单中选择?您能建议实现此目标的任何方法吗?
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.ui import Select
from selenium import webdriver
import time
import urllib.request
import socket
import urllib.error
import requests
from bs4 import BeautifulSoup
import winsound
import time
PROXY=""
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--proxy-server=http://%s' % PROXY)
print('--proxy-server=http://%s' % PROXY)
chrome_driver = "C:/chromewebdriver/chromedriver.exe"
#driver = webdriver.Chrome(chrome_driver, chrome_options=chrome_options) proxy li istem
driver = webdriver.Chrome(chrome_driver) #proxsiz istem
driver.set_page_load_timeout(25) # sahibinden comun proxyden yüklenmesi için en fazla 25 saniye verir
driver.get("https://parselsorgu.tkgm.gov.tr/")
driver.maximize_window()
time.sleep(1)
#-----------------kabul ediyorum butonuna basış
onay=driver.find_element_by_xpath('//*[@id="terms-ok"]')
driver.execute_script("arguments[0].click();", onay)
#-----------------analiz butonuna basış
time.sleep(1)
onay=driver.find_element_by_xpath('//*[@id="analyze-list-link"]')
driver.execute_script("arguments[0].click();", onay)
time.sleep(1.5)
#-------------------analiz tipinin seçimi
dpbox=driver.find_element_by_xpath('//*[@id="analyze-type-region"]/div/select')
dpbox=Select(dpbox)
while len(dpbox.options) == 0:
continue
dpbox.select_by_visible_text('Bağımsız Bölüm Satış')
#-------------------analiz tipinin seçimi
dpbox=driver.find_element_by_xpath('//*[@id="analyze-type-region"]/div/select')
dpbox=Select(dpbox)
while len(dpbox.options) == 0:
continue
dpbox.select_by_visible_text('Bağımsız Bölüm Satış')
#-------------------yıl seçimi 2018
dpbox=driver.find_element_by_xpath('//*[@id="year-region"]/div/select')
dpbox=Select(dpbox)
while len(dpbox.options) == 0:
continue
dpbox.select_by_visible_text('2018')
#-------------------il seçimi ankara
dpbox=driver.find_element_by_xpath('//*[@id="province-select"]')
dpbox=Select(dpbox)
while len(dpbox.options) == 0:
continue
dpbox.select_by_visible_text('Ankara')
time.sleep(100)
答案 0 :(得分:1)
在网络中,@id="province-select"
有两个元素,第一个元素不可见,第二个元素可见,而您的定位符:
dpbox=driver.find_element_by_xpath('//*[@id="province-select"]')
这是指第一个元素,因此,请尝试使用定位符(//*[@id="province-select"])[2]
更改此行,以引用我指的第二个元素,并添加WebDriverWait
以确保该元素准备好单击,然后导入: / p>
from selenium.webdriver.support import expected_conditions
尝试一下:
dpbox.select_by_visible_text('2018')
time.sleep(1)
WebDriverWait(driver, 20).until(expected_conditions.element_to_be_clickable((By.XPATH, '(//*[@id="province-select"])[2]')))
dpbox=driver.find_element_by_xpath('(//*[@id="province-select"])[2]')
dpbox=Select(dpbox)
while len(dpbox.options) == 0:
continue
dpbox.select_by_visible_text('Ankara')