0

Trying to locate an input element which seems to actually have a dynamic property of the input element. This input is inside a td and displays Success or Failure on the webpage and is alongside the text Completion Code. Ive tried xpath and id to find the input element but I am getting "unable to locate element" Once I have that first step above, then I want to pull what is in the value field, which is actually the text displayed on the webpage beside Completion Code. For example

Completion Code Success

My code -

completion_code = driver.find_element(By.XPATH, '//*[@id="code"]')
print(completion_code.text)

The html

<tr>
   <td id="label.code" class="label" type="string" choice="0" height="23px" nowrap="true">
   <label onclick="" for="code" dir="ltr" class="  control-label"><span id="status." mandatory="false" oclass="" aria-label="" class=" required-marker"></span>
   <span class="label-text" data-html="false">Completion code</span>
   </label>
</td>
   <td style="background-color:PaleGreen;width:100%;;" nowrap="true">
   <input autocomplete="off" autocorrect="off" readonly="readonly" name="code" id="code" value="Success" onkeyup="" onchange="onChange('code');" size="" style="border:0px;background:transparent" maxlength="" type="text">
   </td>
</tr>

Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29
anfield
  • 323
  • 3
  • 16
  • Possible duplicate of [Get value of an input box using Selenium (Python)](https://stackoverflow.com/questions/25580569/get-value-of-an-input-box-using-selenium-python) – Navarasu Oct 30 '18 at 20:43
  • I dont think this is a duplicate... I am not locating the element in the first place – anfield Oct 30 '18 at 20:46
  • 1
    Try [to wait for element](https://www.seleniumhq.org/docs/04_webdriver_advanced.jsp#explicit-and-implicit-waits) – Andersson Oct 30 '18 at 20:50

1 Answers1

0

Ok, well it turns out I presumed the wait wasn't a factor it was, added that and the following got the value from the input box which shows the required results

 transform_history = driver.find_element_by_name("code")     
 print(transform_history.get_attribute('value'))
Ashish Kamble
  • 2,555
  • 3
  • 21
  • 29
anfield
  • 323
  • 3
  • 16
  • `String dataID = transform_history.GetAttribute('id');` is what you are looking for from the your question. @anfield i think. – Ashish Kamble Oct 31 '18 at 05:17