-2

It's almost two days that I'm working on getting text values from the tooltips of the Geo chart from the following links:

https://exportpotential.intracen.org/en/markets/geo-map?fromMarker=i&exporter=4&whatMarker=ls&what=6&toMarker=j

The problem is tooltips are visible when hover the mouse cursor on them. What I did, is clicking on respective items and get values. But the problem is some items are not clickable. The code I'm using for this is:

all_nodes = driver.find_element(By.CSS_SELECTOR, ".flamingo.chart").find_elements(By.CSS_SELECTOR, ".node")

for node in all_nodes:
    node.find_element(By.CSS_SELECTOR, ".circle.total").click()
    country = driver.find_element(By.CSS_SELECTOR, ".tooltip-title").text.strip()

but when I use this code I get:

Message: element click intercepted: Element <circle class="circle total IND" cx="0" cy="0" r="65" style="fill: rgba(158, 106, 117, 0.6);"></circle> is not clickable at point (830, 543). Other element would receive the click: <circle class="circle perc IRQ" cx="0" cy="0" r="61.56828206861062" style="fill: rgb(158, 106, 117);"></circle>
  (Session info: chrome=114.0.5735.133)
Stacktrace:
0   chromedriver                        0x000000010c8d56b8 chromedriver + 4937400
1   chromedriver                        0x000000010c8ccb73 chromedriver + 4901747
2   chromedriver                        0x000000010c48a616 chromedriver + 435734
3   chromedriver                        0x000000010c4d5b97 chromedriver + 744343
4   chromedriver                        0x000000010c4d3450 chromedriver + 734288
5   chromedriver                        0x000000010c4d0a84 chromedriver + 723588
6   chromedriver                        0x000000010c4cfbe4 chromedriver + 719844
7   chromedriver                        0x000000010c4c21e1 chromedriver + 664033
8   chromedriver                        0x000000010c4f2012 chromedriver + 860178
9   chromedriver                        0x000000010c4c19c1 chromedriver + 661953
10  chromedriver                        0x000000010c4f21ce chromedriver + 860622
11  chromedriver                        0x000000010c50ce76 chromedriver + 970358
12  chromedriver                        0x000000010c4f1de3 chromedriver + 859619
13  chromedriver                        0x000000010c4bfd7f chromedriver + 654719
14  chromedriver                        0x000000010c4c10de chromedriver + 659678
15  chromedriver                        0x000000010c8912ad chromedriver + 4657837
16  chromedriver                        0x000000010c896130 chromedriver + 4677936
17  chromedriver                        0x000000010c89cdef chromedriver + 4705775
18  chromedriver                        0x000000010c89705a chromedriver + 4681818
19  chromedriver                        0x000000010c86992c chromedriver + 4495660
20  chromedriver                        0x000000010c8b4838 chromedriver + 4802616
21  chromedriver                        0x000000010c8b49b7 chromedriver + 4802999
22  chromedriver                        0x000000010c8c599f chromedriver + 4872607
23  libsystem_pthread.dylib             0x00007fff2050c8fc _pthread_start + 224
24  libsystem_pthread.dylib             0x00007fff20508443 thread_start + 15
Mahdi
  • 967
  • 4
  • 18
  • 34

2 Answers2

1

Here is the full working solution:

import time

from selenium.webdriver import Chrome, ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.wait import WebDriverWait
import selenium.webdriver.support.expected_conditions as EC

driver = Chrome()
driver.maximize_window()
action = ActionChains(driver)
driver.get("https://exportpotential.intracen.org/en/markets/geo-map?fromMarker=i&exporter=4&whatMarker=ls&what=6&toMarker=j")
wait = WebDriverWait(driver, 30)
circle_elements = wait.until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".circle.total")))

for each_circle in circle_elements:
    driver.find_element(By.XPATH, "//h1[text()='Export Potential Map']").click()
    time.sleep(2)
    action.move_to_element(each_circle).perform()
    country = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, ".tooltip-title")))
    print(country.text)

Result:

India
Pakistan
China
United Arab Emirates
United States
Saudi Arabia
Germany
France
Türkiye
Spain
Italy
Jordan
Iran, Islamic Republic of
Russian Federation
United Kingdom
Canada
Egypt
Mexico
Singapore
Kazakhstan
Australia
Tunisia
Poland
Austria
Belgium
Uzbekistan
Netherlands
Portugal
Kuwait
Morocco
Romania
Lithuania
South Africa
Japan
Bahrain
Lebanon
Korea, Republic of
Finland
Brazil
Belarus
Israel
Switzerland
Sweden
Greece
Ireland
Czechia
Malaysia
Qatar
Zambia
Tajikistan

Process finished with exit code 0

Explanation: You can use Selenium's ActionChains class and its move_to_element method to perform mouse hover(You can see that in code above in the for loop). Also, in the each iteration in the loop, you need to be careful that the desired element is not overlapped by some other element(This was the root cause of your code).

Shawn
  • 4,064
  • 2
  • 11
  • 23
0

Instead of simply clicking use ActionChains to move_to_element(to_element) and invoke click and you can use either of the following locator strategies:

  • Code block:

    driver.get("https://exportpotential.intracen.org/en/markets/geo-map?fromMarker=i&exporter=4&whatMarker=ls&what=6&toMarker=j")
    elements = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, ".flamingo.chart .node")))
    for ele in elements:
      ActionChains(driver).move_to_element(ele).click().perform()
      print(WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "app-chart-tooltip > div#tooltip-content"))).text)
    
  • Console output:

    India
    Export potential
    $191 mn
    Actual exports
    $110 mn
    Unrealized potential remaining in individual products
    $83 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    India
    Export potential
    $191 mn
    Actual exports
    $110 mn
    Unrealized potential remaining in individual products
    $83 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    India
    Export potential
    $191 mn
    Actual exports
    $110 mn
    Unrealized potential remaining in individual products
    $83 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    United Arab Emirates
    Export potential
    $6.1 mn
    Actual exports
    $1.5 mn
    Unrealized potential remaining in individual products
    $5.5 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    United Arab Emirates
    Export potential
    $6.1 mn
    Actual exports
    $1.5 mn
    Unrealized potential remaining in individual products
    $5.5 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    Saudi Arabia
    Export potential
    $2.7 mn
    Actual exports
    $520 k
    Unrealized potential remaining in individual products
    $2.4 mn
    
    For this country find
    PRODUCTS
    EXPORTERS
    United Kingdom
    Export potential
    $224 k
    Actual exports
    $20 k
    Unrealized potential remaining in individual products
    $213 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    United Kingdom
    Export potential
    $224 k
    Actual exports
    $20 k
    Unrealized potential remaining in individual products
    $213 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Egypt
    Export potential
    $141 k
    Actual exports
    $163 k
    Unrealized potential remaining in individual products
    $125 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Egypt
    Export potential
    $141 k
    Actual exports
    $163 k
    Unrealized potential remaining in individual products
    $125 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Singapore
    Export potential
    $110 k
    Actual exports
    $0
    Unrealized potential remaining in individual products
    $110 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Singapore
    Export potential
    $110 k
    Actual exports
    $0
    Unrealized potential remaining in individual products
    $110 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Singapore
    Export potential
    $110 k
    Actual exports
    $0
    Unrealized potential remaining in individual products
    $110 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Tunisia
    Export potential
    $86 k
    Actual exports
    $81 k
    Unrealized potential remaining in individual products
    $5.1 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Tunisia
    Export potential
    $86 k
    Actual exports
    $81 k
    Unrealized potential remaining in individual products
    $5.1 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Tunisia
    Export potential
    $86 k
    Actual exports
    $81 k
    Unrealized potential remaining in individual products
    $5.1 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Belgium
    Export potential
    $62 k
    Actual exports
    $2.3 k
    Unrealized potential remaining in individual products
    $60 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Belgium
    Export potential
    $62 k
    Actual exports
    $2.3 k
    Unrealized potential remaining in individual products
    $60 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Belgium
    Export potential
    $62 k
    Actual exports
    $2.3 k
    Unrealized potential remaining in individual products
    $60 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    Portugal
    Export potential
    $57 k
    Actual exports
    $0
    Unrealized potential remaining in individual products
    $57 k
    
    For this country find
    PRODUCTS
    EXPORTERS
    ...
    ...
    ...
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I think not all countries are displayed in your console output. Some of them are missed. – Shawn Jun 23 '23 at 16:06