Python Forum
Selenium Python for Dropdown not working
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium Python for Dropdown not working
#1
Hi All,

We have an internal dynamics CRM page that we are trying to download data from using Selenium. Unfortunately when I get into the second window that opens up, the dropdown selection does not seem to work. It is the "Select Agreements" code below:
Below is the code
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC

#--| Chrome Setup
options = webdriver.ChromeOptions()
# options.add_argument("--headless")
options.add_argument('--disable-gpu')
options.add_argument('--log-level=3')
prefs={"download.default_directory":r"\\energy\data\apps\BISharedServices\LegacyNGLForecastArchive"}



#Setup Chrome preferences
options.add_experimental_option("prefs",prefs)
browser = webdriver.Chrome(chrome_options=options)

#Direct Link 
browser.get('')
browser.maximize_window()

# Store current window position
window_before = browser.window_handles[0]


wait = WebDriverWait(browser, 30)

#Key in Email
web_loginscreen = wait.until(EC.element_to_be_clickable((By.ID, 'i0116')))  
web_loginscreen.send_keys("")

# Next Button
web_loginbutton = browser.find_element_by_xpath('//*[@id="idSIButton9"]')
web_loginbutton.click()

window_before_title = browser.title
print(window_before_title)
#Filter button 
web_filter = wait.until(EC.element_to_be_clickable((By.XPATH, '//*[@id="advancedFindLauncher"]/button/span/span')))  
web_filter.click()

#browse to newly opened download window
browser.switch_to.window(browser.window_handles[1])
window_after = browser.window_handles[1]
window_after_title = browser.title
print(window_after_title)

# Select Agreements
time.sleep(5)
dropdown = browser.find_element_by_xpath('//*[@id="slctPrimaryEntity"]')
select = Select(dropdown)
select.selectByIndex(35)


time.sleep(15) #seconds
browser.close()
browser.quit()


The Xpath for the dropdown is //*[@id="slctPrimaryEntity"] and the selection "Agreements" from the dropdown is option 35
Xpath for the selection = //*[@id="slctPrimaryEntity"]/option[35]

The Error I get is below
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="slctPrimaryEntity"]"}
(Session info: chrome=86.0.4240.111)




Do you find anything wrong with my python code syntax in accessing the dropdown?
Any help is appreciated. Please advise.

Thanks.
Reply
#2
UPDATE

I was able to figure out that I needed to switch to a different iframe and then try the element and that worked. But now my final step to click the export button is not working as that ribbon is automatically generated.

Does anyone know how to switch to a dynamic tab on the toolbar?

# Select Agreements
time.sleep(5)


  # locate all elements
 

frame = browser.find_element_by_xpath('//*[@id="contentIFrame0"]')
browser.switch_to.frame(frame)
# 

dropdown = browser.find_element_by_xpath('//*[@id="slctPrimaryEntity"]')
dropdown.click()

agreements = browser.find_element_by_xpath('//*[@id="slctPrimaryEntity"]/option[35]')
agreements.click()
# print(dropdown.text)

# Go back out of iframe to default content
browser.switch_to.default_content()
# Look For Results
web_results = browser.find_element_by_xpath('//*[@id="apttusps.ApplicationRibbon.{!EntityLogicalName}.Button2.Button-Large"]') 
web_results.click()

ribbonframe = browser.find_element_by_xpath('//*[@id="crmRibbonManager"]')
ribbonframe.click()

# browser.switch_to.frame(ribbonframe)

# Export to Excel
web_results_excel = browser.find_element_by_class_name('ms-cui-ctl-large')
# find_element_by_xpath('//*[@id="apttus_apts_agreement|NoRelationship|SubGridStandard|Mscrm.SubGrid.apttus_apts_agreement.ExportToExcel-Large"]')
web_results_excel.click()

time.sleep(15) #seconds
browser.close()
browser.quit()
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Generating dynamic dropdown list test 1 1,471 Aug-30-2023, 08:00 AM
Last Post: blessinguvula
  Python Selenium (Dropdown-) data Robin_at_Cantelli 2 6,198 Dec-29-2021, 03:16 AM
Last Post: ondreweil
  Dropdown interact moisesfelipee 0 1,677 May-04-2020, 01:11 AM
Last Post: moisesfelipee
  Hyperlink Click is not working in Selenium webdriver rajeev1729 0 2,025 May-02-2020, 11:21 AM
Last Post: rajeev1729
  While loop skips multiple dropdown menu options and then works as intended newbie_programmer 1 2,877 Dec-23-2019, 10:26 PM
Last Post: keuninkske
  How can i scrape dropdown value ? caca 0 2,981 Nov-03-2019, 11:24 PM
Last Post: caca
  Python Flask Dependent Dropdown Anfaa 3 18,452 Oct-24-2018, 09:35 PM
Last Post: nilamo
  Simple Element Check Code in Selenium Not Working digitalmatic7 1 3,008 Feb-18-2018, 06:53 AM
Last Post: metulburr
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,626 Nov-03-2017, 08:41 PM
Last Post: metulburr
  Click dropdown menu option with Selenium PyChrome AcszE 3 5,924 Oct-26-2017, 10:07 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020