无法从类似盒子的容器中获取标题 [英] Can't fetch titles from some box-like containers
本文介绍了无法从类似盒子的容器中获取标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经在python
中与selenium
相关联地编写了一个脚本,以单击网页中地图上可用的一些点.单击一个点时,会弹出一个包含相关信息的小框.
I've written a script in python
in association with selenium
to click on some dots available on a map in a web page. When a dot is clicked, a small box containing relevant information pops up.
我想解析每个框的标题.当我执行脚本时,单击一个点会引发错误.我怎样才能成功?
I would like to parse the title of each box. When I execute my script, it throws an error while clicking on a dot. How can I make a go successfully?
这是脚本:
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
link = "replace with above link"
driver = webdriver.Chrome()
driver.get(link)
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,"#mapDiv_zoom_slider .esriSimpleSliderIncrementButton"))).click()
for item in wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR,"#NWQMC_VM_directory_June2016_3915_0_layer circle"))):
item.click()
我遇到错误:
line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <circle fill="rgb(237, 81, 81)" fill-opacity="1" stroke="rgb(153, 153, 153)" stroke-opacity="1" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="4" cx="720" cy="430" r="4" transform="matrix(1.00000000,0.00000000,0.00000000,1.00000000,0.00000000,0.00000000)" fill-rule="evenodd" stroke-dasharray="none" dojoGfxStrokeStyle="solid"></circle> is not clickable at point (720, 430). Other element would receive the click: <circle fill="rgb(20, 158, 206)" fill-opacity="1" stroke="rgb(153, 153, 153)" stroke-opacity="1" stroke-width="1" stroke-linecap="butt" stroke-linejoin="miter" stroke-miterlimit="4" cx="720" cy="430" r="4" transform="matrix(1.00000000,0.00000000,0.00000000,1.00000000,0.00000000,0.00000000)" fill-rule="evenodd" stroke-dasharray="none" dojoGfxStrokeStyle="solid"></circle>
(Session info: chrome=67.0.3396.99)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.1.7601 SP1 x86)
这是弹出框的方式:
推荐答案
@Andrei Suvorkov真的很亲密(+1)
@Andrei Suvorkov was really close (+1)
尝试下面的代码以获取所需的输出:
Try below code to get required output:
from selenium.webdriver.common.action_chains import ActionChains
driver = webdriver.Chrome()
driver.get(link)
wait = WebDriverWait(driver, 5)
driver.maximize_window()
items = wait.until(EC.presence_of_all_elements_located((By.XPATH, "//*[name()='svg']//*[name()='circle']")))
for item in items:
ActionChains(driver).move_to_element(item).click(item).perform()
popup = wait.until(EC.visibility_of_element_located((By.CLASS_NAME, "contentPane")))
print(popup.text)
wait.until(EC.visibility_of_element_located((By.XPATH, "//div[contains(@class, 'close')]"))).click()
这篇关于无法从类似盒子的容器中获取标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文