Mi Po
Mi Po

Reputation: 1213

Python Selenium, edge browser, I dont see Inspect Element on every element

  1. I am trying to get data from a Power Bi table. There are some elements that appear when hovering over a table. When I right click on ... I don't see Inspect Element. However, when I left click on this element, I can see a menu, and if I right click on any items, I can see Inspect element. My first question, is why I don't see Inspect Element in the right click menu for all elements in the browser. Am I somehow able to open this ... menu programmatically in Selenium?

  2. the Export Data element only appears in HTML after the first left click. I'm assuming this is created using Javascript and in order to export data with Selenium I would have to programmatically instantiate this by clicking on the ... menu. Is selenium capable of triggering javascript functions that generate more html code in a dynamic webpage? Or do I need to somehow click on the ... element.

  3. If I can execute a javascript function, how can I find out in Edge the javascript function that gets executed and how can I replicate this function in Selenium

Essentially, if I try to find the Export data element in Selenium, it is not able to find it, unless I set a breakpoint before search, then in EdgeDriver I open this menu, and then I can find it and click it through Python

  1. If all else fails, can I programmatically open the left click menu by automating a mouse click at certain coordinates in Selenium?

... right click doesn't have Inspect Element

The left click menu does have inspect element

Upvotes: 2

Views: 928

Answers (2)

Wouter
Wouter

Reputation: 1336

Many thanks to r000bin, this solution works for me, downloading data from PowerBI using Selenium for Python:

import selenium, mouse, time
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.common.action_chains import ActionChains

url = 'https://dataport.gasunie.nl/Vulling-Gasopslagen-Nederland'
driver = selenium.webdriver.Chrome(service=Service())
driver.get(url)
time.sleep(4)
#driver.fullscreen_window()
#driver.switch_to.window(driver.current_window_handle)
time.sleep(4)
iframe = driver.find_elements(By.TAG_NAME, 'iframe')
assert len(iframe)==1
driver.switch_to.frame(iframe[0])
time.sleep(4)

from selenium.webdriver.common.action_chains import ActionChains
actions = ActionChains(driver)
actions.move_to_element_with_offset(driver.find_element(By.TAG_NAME, 'html'), 0,0)
actions.move_by_offset('5', '5').click().perform()
    
time.sleep(4)
button = driver.find_element(By.CLASS_NAME, 'vcMenuBtn')
button.click()
button = driver.find_element(By.ID, '0')
button.click()

# 4 tabs and 1 enter
time.sleep(4)
for n in range(4):
    element = driver.switch_to.active_element
    time.sleep(2)
    element.send_keys(Keys.TAB)
    time.sleep(2)

element = driver.switch_to.active_element
time.sleep(2)
element.send_keys(Keys.ENTER)
driver.close()

Upvotes: 1

r000bin
r000bin

Reputation: 663

1.1 why I don't see Inspect Element in the right click menu for all elements: PowerBi has its own context menu so they suppress the browsers context menu. If the element is tricky to find the dev tools, you can press Ctrl + Shift + C (while dev tools is open) and then click the desired element. Your mouse needs to be already over the element before pressing the key combination. dev tools inspect elements with hotkeys

1.2 Am I somehow able to open this ... menu programmatically in Selenium? Seems a little tricky, but could work if you first find the title of that area and move the mouse there, like described here: https://stackoverflow.com/a/8261754/12914172

Then your element should be in the html and you can find it hopefully by its class name vcMenuBtn that seems to be unique on that page. But you need to verify that.

2. Is selenium capable of triggering javascript functions that generate more html code in a dynamic webpage? Or do I need to somehow click on the ... element. Selenium is able to execute javascript like desribed here: https://stackoverflow.com/a/70544802/12914172

However in your sample, and I was quickly checking the PowerBI online page, this looks like a whole lot of reverse engineering to understand and can sometimes be dangerous as well. I would go for hoover over the area find the ... and click it.

3. How can I find out in Edge the javascript function that gets executed In dev tools you can set breakpoints to debug the steps the pages does after an action. But again, I would not invest to much time in that. debugging in dev tools

4. Can I programmatically open the left click menu by automating a mouse click at certain coordinates in Selenium? Yes but this never works as good as the way described above. If you still want to give it a try, maybe that answer helps: https://stackoverflow.com/a/26385456/12914172

Upvotes: 3

Related Questions