I’m trying to a script to pull reports from a client’s site here: https://ww360.azurewebsites.net/account/login, and I’m trying to get the script to select “change” to make the pop up window come up and select the particular location to pull reports for, and I haven’t been able to get it to work. Tried selecting by xpath, css, text, and link, won’t go through.
#Import packages
from selenium import webdriver
from selenium.webdriver import Chrome
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.support.select import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.common.by import By
from datetime import datetime
from selenium.webdriver.common.keys import Keys
import win32com.client
import glob
import os
from selenium.webdriver.support.ui import Select
# set directory and import drivers
chrome_options = webdriver.ChromeOptions()
prefs = {'download.default_directory' : r'C:\Users\Austin Vanderlyn\Downloads', "download.prompt_for_download": False}
chrome_options.add_experimental_option('prefs', prefs)
driver = webdriver.Chrome(service=Service(executable_path=r"G:\Analytics\_chromedriver\chromedriver.exe"), options=chrome_options)
# opens a chrome window to go to the window world portal
time.sleep(5)
driver.get("https://ww360.azurewebsites.net/account/login")
time.sleep(5)
# select the change button
element=WebDriverWait(driver,30).until(
EC.element_to_be_clickable((By.XPATH, "/html/body/app-root/ng-component/div/div/div[1]/div/div/div[1]/div[2]/tenant-change/span/a")))
element.click()
Does anyone know why this is not working?
You are very close. You are getting below exception:
Problem: Another element is obstructing your
click()action.Solution1: Just maximise the window before performing the click. Use
maximize_window()code after launching the URL, see below:Solution2: If despite maximising the window issue persist, then try to perform
click()usingJavaScriptas below:On another note, SUGGESTION: Try to avoid using absolute XPath expressions and use relative XPaths, as the latter are more reliable.
Change the below:
TO: