Python Forum

Full Version: Find Dynamic Input Element Class Problem
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi All

I'm new to this group and trust me I have searched high and low to get this answer but now having to resort to asking for help.

I need to clear the content of an input box its class=masterCustomDropDown the problem there is 7 of these on the web page which is OracleBI. All are the identical class and every attribute is the same. The only differentiating part is the ID which is dynamic. The id for the input box i need to clear is 'saw_#####_#_1' the # can be any length the problem is there is other ID's on the page that also start and end with this.

What i have noticed is the input id usually 95% of the time does end in either _9_1 or _5_1 but i have seen or a rare occasion _7_1

Here is snippet of the html

<table>
<tbody>
	<tr><td style="vertical-align: top; white-space: pre-wrap;" class="masterPrompt promptLabel promptLabelLeftAlign">
	<label for="saw_1063346_9_op" title="Division"><span>Division</span>
	</label>
	</td>
	</tr>
<tr>
 <td style="vertical-align: middle; text-align: left;">
  <span>
   <span class="data promptControlNarrowView" style="white-space: nowrap;">
    <div>
	 <div style="white-space: nowrap; vertical-align: bottom; width: 120px;" class="masterCustomDropDown">
	  <input id="saw_1063346_9_1" type="text" class="promptTextField" tabindex="0" title="North" style="width: 97px;">
	  <img id="saw_1063346_9_1_dropdownIcon" tabindex="-1" src="/analytics/res/v-DBoTHFvj6ls/s_Alta/master/selectdropdown_ena.png" 
	  title="" alt="" style="cursor: pointer;" class="promptComboBoxButtonMoz" closingdropdownmenu="false">
	  <div style="width: 0px; height: 0px; overflow: hidden; position: absolute; z-index: 1;">
	  <label id="saw_1063346_9_1_aria_label">
	  <span><span stext="">
	  </span>
	  <span stext=". ">. </span>
	  <span stext="Division">Division</span>
	  <span stext=", ">, </span>
	  <span stext=""></span>
	  <span stext=", ">, </span>
	  <span stext="Multiple Values ComboBox">
I have tried using the below with no success:
try:
    elem = driver.find_element_by_xpath("//input[starts-with(@id, 'saw') and contains(@id, '_9_1')]")
    elem.clear()



Help and thoughts much appreciated.