css - Selenium Webdriver Python select a dropdown error local variable element referenced before assignment -
this question has answer here:
i trying select drop down element getting error
error traceback (most recent call last): file "c:\webdriver\clearcore\testcases\operationspage_testcase.py", line 59, in test_add_and_run_clean_process process_lists_page.click_select_a_preview_to_import_configuration_from_dropdown_from_clean_task_tab(globals.datapreview_crm_name) file "c:\webdriver\clearcore\pages\operations.py", line 113, in click_select_a_preview_to_import_configuration_from_dropdown_from_clean_task_tab select = (select(self.get_element(by.xpath, 'html/body/div[2]/div[2]/div/div[4]/div/div[2]/div/div[3]/div/div[7]/div/div[3]/div/div[4]/div/div[2]/div/div[4]/div/div[3]/div/div[3]/div/div[4]/div/div[2]/div/div[3]/div/div[2]/div/div[3]/div/div[3]/div/div/div/div/div[1]/div[1]/div[2]/span[10]/span/select'))) file "c:\webdriver\clearcore 501\pages\base.py", line 31, in get_element return element unboundlocalerror: local variable 'element' referenced before assignment
my method implementation is:
def click_select_a_preview_to_import_configuration_from_dropdown_from_clean_task_tab(self, data_preview_name): #select = select(by.xpath, '//span[contains(text(), "select data preview import configuration from")]/preceding::span[1]//../span//../select') #select = (select(webdriverwait(self.driver, 20).until(ec.element_to_be_clickable((by.xpath, '//span[contains(text(), "select data preview import configuration from")]/preceding::span[1]//../span//../select'))))) #select = (select(webdriverwait(self.driver, 20).until(ec.element_to_be_clickable((by.xpath, 'html/body/div[2]/div[2]/div/div[4]/div/div[2]/div/div[3]/div/div[7]/div/div[3]/div/div[4]/div/div[2]/div/div[4]/div/div[3]/div/div[3]/div/div[4]/div/div[2]/div/div[3]/div/div[2]/div/div[3]/div/div[3]/div/div/div/div/div[1]/div[1]/div[2]/div/span[10]/span/select'))))) select = (select(self.get_element(by.xpath, 'html/body/div[2]/div[2]/div/div[4]/div/div[2]/div/div[3]/div/div[7]/div/div[3]/div/div[4]/div/div[2]/div/div[4]/div/div[3]/div/div[3]/div/div[4]/div/div[2]/div/div[3]/div/div[2]/div/div[3]/div/div[3]/div/div/div/div/div[1]/div[1]/div[2]/span[10]/span/select'))) print select.options print [o.text o in select.options] # these string-s select.select_by_visible_text(str(data_preview_name)) return self
get_element implementation is:
# returns element if found def get_element(self, how, what): # params how: locator type # params what: locator value try: element = self.driver.find_element(by=how, value=what) except nosuchelementexception, e: print print "element not found " print e return element
the method call drop down testcase class is:
process_lists_page.click_select_a_preview_to_import_configuration_from_dropdown_from_clean_task_tab("selenium_lademo_crm_donotchange")
the html is:
<div id="operations_add_process_list_tab_groups_tab_standard_1"> <span/> <span> <span class="" title="" style="font-weight:bold;">select data preview import configuration from</span> </span> <span> <span/> <span/> <span/> <span/> <span/> <span> <span class="" title="none" style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;empty-cells:show;"> <select tabindex="-1"> <option selected="selected" value="none">none</option> <option value="crminvalid_07102015">crminvalid_07102015</option> <option value="lademo_crm2_chrome">lademo_crm2_chrome</option> <option value="lademo_crm_donotchange_chrome">lademo_crm_donotchange_chrome</option> <option value="lademo_escr_do_no_change_chrome">lademo_escr_do_no_change_chrome</option> <option value="lademo_odb_data">lademo_odb_data</option> <option value="megaone_07102015">megaone_07102015</option> <option value="riaznoquotesutf8">riaznoquotesutf8</option> <option value="selenium_lademo_crm_donotchange">selenium_lademo_crm_donotchange</option> <option value="selenium_lademo_escr_donotchange">selenium_lademo_escr_donotchange</option> <option value="selenium_lademo_orchard_donotchange">selenium_lademo_orchard_donotchange</option> <option value="test">test</option> <option value="_crm_donotchange">_crm_donotchange</option> </select> </span> </span> </div>
why getting error? race condition, element not yet visible? have tried using webdriverwait, same error.
from drop down select value "selenium_lademo_crm_donotchange"
thanks, riaz
you using "private" method find element.
according description:
find_element(by='id', value=none)
‘private’ method used find_element_by_* methods.
usage: use corresponding find_element_by_* instead of this.
try changing:
element = self.driver.find_element(by=how, value=what)
for:
element = self.driver.find_element_by_xpath(value=what)
Comments
Post a Comment