0

I've been trying to figure out this error for serveral hours until now..

I tried to click the red button on the screen, but somehow I can't use the xpath method.

The error message waas given right this:

Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="mapContainer"]"}
  (Session info: chrome=107.0.5304.107)

My goal is to crawl the information of a popup screen showed when the button was clicked.


from selenium import webdriver  # 셀레니움을 활성화
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time
import pandas as pd
import numpy as np
import re
from datetime import datetime

dr = webdriver.Chrome()  # 크롬 드라이버를 실행하는 명령어를 dr로 지정
dr.get('https://rawris-am.ekr.or.kr/wrms/')  # 드라이버를 통해 url의 웹 페이지를 오픈
time.sleep(2)  #2초 대기
act = ActionChains(dr)  # 드라이버에 동작을 실행시키는 명령어를 act로 지정

dr.switch_to.frame('DivMapOpenLayers')
time.sleep(1)

element1 = dr.find_element(By.XPATH, '//*[@id="xcontainer_reservoir"]/table[2]/tbody/tr/td/div[1]/label[1]/input')

CHOICE = {'경기':2, '강원':3, '충북':4, '충남':5, '전북':6, '전남':7, '경북':8, '경남':9, '제주':10}
CHOICE = CHOICE.get('전남') 
dr.find_element(By.XPATH, f'//*[@id="xcontainer_reservoir"]/table[3]/tbody/tr[{CHOICE}]/td[2]').click()

res_detail = dr.find_element(By.XPATH, f'//*[@id="xcontainer_reservoir"]/table[3]/tbody/tr[2]/td[2]').click()

res_detail = dr.find_element(By.XPATH, f'//*[@id="xcontainer_reservoir"]/table[3]/tbody/tr[2]/td[2]').click()

ee = dr.find_element(By.XPATH, '//*[@id="mapContainer"]')  # error caused
ee.get_attribute('style')
dr.execute_script("arguments[0].setAttribute('style','display: block;')", ee);
ee.get_attribute('style')

1. before putting mouse cursor on the point

2. when i put mouse cursor on the red point

site url : https://rawris-am.ekr.or.kr/wrms/ thanks for advance!!

Marie
  • 1
  • 1
  • Can you try if [switching to the active element](https://stackoverflow.com/a/41315273/5189811) and querying it gets the information from the popup? – Oluwafemi Sule Nov 23 '22 at 06:45

1 Answers1

0

I don't think you are doing much wrong. Adding explicit waits will always improve reliability as you are less vulnerable to timing issues:

iframe = WebDriverWait(dr, 10).until(EC.presence_of_element_located((By.ID, "DivMapOpenLayers")))
driver.switch_to.frame(iframe)
CHOICE = {'경기':2, '강원':3, '충북':4, '충남':5, '전북':6, '전남':7, '경북':8, '경남':9, '제주':10}
CHOICE = CHOICE.get('전남') 
WebDriverWait(dr, 10).until(EC.presence_of_element_located((By.XPATH, f'//*[@id="xcontainer_reservoir"]/table[3]/tbody/tr[{CHOICE}]/td[2]'))).click()
WebDriverWait(dr, 10).until(EC.presence_of_element_located((By.XPATH, f'//*[@id="xcontainer_reservoir"]/table[3]/tbody/tr[2]/td[2]'))).click()
ee = WebDriverWait(dr, 10).until(EC.presence_of_element_located((By.XPATH, '//*[@id="mapContainer"]')))
print(ee.get_attribute("textContent"))
Easty77
  • 470
  • 2
  • 7