I try to scrape data from the public Microsoft Power Bi Dashboard (4th page).
But unfortunately, I can't understand how with selenium I can change periods of time.
Tell me, please, is this even possible using python selenium? Maybe move these sliders, or enter dates into inputs. Thanks. Dashboard screen
Here is my code to load the dashboard page:
from selenium import webdriver
import time
fp = webdriver.FirefoxProfile()
url='https://app.powerbi.com/view?r=eyJrIjoiNjIwNzg5NzQtNzRlYS00YzFmLWJiNTUtOTM2MGEwY2FjOGJlIiwidCI6ImE3NWRkYWZlLWQ2MmYtNGIxOS04NThhLTllYzFhYjI1NDdkNCIsImMiOjl9'
driver = webdriver.Firefox(firefox_profile=fp)
driver.get(url)
time.sleep(5)
driver.find_element_by_xpath('//*[@id="embedWrapperID"]/div[2]/logo-bar/div/div/div/logo-bar-navigation/span/button[2]/i').click()
driver.find_element_by_xpath('//*[@id="embedWrapperID"]/div[2]/logo-bar/div/div/div/logo-bar-navigation/span/button[2]/i').click()
driver.find_element_by_xpath('//*[@id="embedWrapperID"]/div[2]/logo-bar/div/div/div/logo-bar-navigation/span/button[2]/i').click()
CodePudding user response:
I was able to get it to set the date by clearing the existing date, and then using a date string tab to refresh the graph, is that what you are looking for?
I also packaged up my attempts to click on the various items with a wait function so I'm not waiting some unnecessary amount of time before something shows up on the screen.
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.common import exceptions
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.keys import Keys
def InputByXPATH(NameOfObject, WhatToSend):
try:
item = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.XPATH, NameOfObject)))
item.click()
item.send_keys(Keys.CONTROL, 'a')
item.send_keys(WhatToSend)
except TimeoutException as e:
print("InputByXPATH Error: Couldn't input by XPATH on: " str(NameOfObject))
pass
def ClickByXPATH(NameOfObject):
try:
item = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, NameOfObject)))
item.click()
except TimeoutException as e:
print("ClickByXpath Error: Couldn't Click by XPATH on: " str(NameOfObject))
pass
driver = webdriver.Chrome()
driver.maximize_window()
url='https://app.powerbi.com/view?r=eyJrIjoiNjIwNzg5NzQtNzRlYS00YzFmLWJiNTUtOTM2MGEwY2FjOGJlIiwidCI6ImE3NWRkYWZlLWQ2MmYtNGIxOS04NThhLTllYzFhYjI1NDdkNCIsImMiOjl9'
driver.get(url)
ClickByXPATH('//*[@id="embedWrapperID"]/div[2]/logo-bar/div/div/div/logo-bar-navigation/span/button[2]/i')
ClickByXPATH('//*[@id="embedWrapperID"]/div[2]/logo-bar/div/div/div/logo-bar-navigation/span/button[2]/i')
InputByXPATH('/html/body/div[1]/report-embed/div/div/div[1]/div/div/div/exploration-container/div/div/div/exploration-host/div/div/exploration/div/explore-canvas/div/div[2]/div/div[2]/div[2]/visual-container-repeat/visual-container[8]/transform/div/div[3]/div/visual-modern/div/div/div[2]/div/div[1]/div/div[1]/input', '2/1/2022' Keys.TAB )
time.sleep(10)