0

I can't find an element by Id, name or xpath. My code is the below:

#Begin the Automation of WIPs !
time.sleep(3)
keyboard.press(Key.tab)
keyboard.release(Key.tab)
#keyboard.type(str(number)) #This types the Part Number
keyboard.type(str('C2777-MX45D-39114TG7XA700'))
keyboard.press(Key.tab)
keyboard.release(Key.tab)

time.sleep(2)
qty_case = browser.find_element_by_name('txtQuantity_DEC')
qty_case.broswer.send_keys('50')

I'm trying to select the "txtQuantity_Dec" id, see code below:

<tbody class="Section DefaultColor">

          <tr>
            <td class="FieldLabelCell">Quantity per Container:</td>
            <td class="FieldControlCell">
              <input type="hidden" id="**txtQuantity_DEC**" name="txtQuantity_DEC" value="" dredd="Quantity per Container" revision="false">
<input maxlength="10" size="5" type="text" id="txttxtQuantity_DEC" name="txttxtQuantity_DEC" revisionlabel="Quantity per Container" value="0" revision="True" dredd_validate="false" num_disp="true" style="text-align:right;" onkeypress="javascript:var ivKeyCode = plEventKey(event); if ( (ivKeyCode >= 48 &amp;&amp; ivKeyCode <= 57)  || ivKeyCode == 45  || ivKeyCode == 8  || ivKeyCode == 9  || ivKeyCode == 44  || ivKeyCode == 46 ) { return true; } else { return false; }" invert="false" usa="true" onblur="var svUserVal = document.getElementById('txttxtQuantity_DEC').value; svUserVal = String(svUserVal).replace(/,/g, '');document.getElementById('txtQuantity_DEC').value = svUserVal;" onkeyup="var svUserVal = document.getElementById('txttxtQuantity_DEC').value; svUserVal = String(svUserVal).replace(/,/g, '');document.getElementById('txtQuantity_DEC').value = svUserVal;if (window.event.keyCode == 13) FormSubmit('Inventory_Add_Modify.asp?Do=Add');" onchange="var svUserVal = document.getElementById('txttxtQuantity_DEC').value; svUserVal = String(svUserVal).replace(/,/g, '');document.getElementById('txtQuantity_DEC').value = svUserVal;QuantityChange();">

And this is the error I get when I run my code:

Message: no such element: Unable to locate element: {"method":"css selector","selector":"[name="txtQuantity_DEC"]"}

I've tried doing it by id, name, and xpath. Any idea why selenium can't find the text box I'm trying to select ?

jthesimple
  • 39
  • 6
  • 1
    Can you share the entire html or a link to it please? – RKelley Apr 05 '20 at 23:38
  • 1
    Check if the element is present in the iframe. You can try with `//input[@name='txtQuantity_DEC']/ancestor::html` xpath in the [devtools](https://stackoverflow.com/questions/55870609/is-there-a-way-to-learn-xpath-without-using-firebug-or-xpath-as-firefox-is-not-s/55870909#55870909) to check if the element is in iframe. – supputuri Apr 05 '20 at 23:46
  • @suppturi can you elaborate on iframe? what implications would it have if the element is not/is in the iframe? – jthesimple Apr 06 '20 at 00:06
  • Have you tried waiting for the element ? can we see some more code? – 0m3r Apr 06 '20 at 01:51
  • @0m3r yes I have a 2 second wait, see updated code. – jthesimple Apr 06 '20 at 02:47
  • @jthesimple if your table is located inside an iframe (i.e. you have an iframe tag in the ancestors of the table when you go up in the DOM) it means everything under the iframe is in a different document than the rest of the DOM. And if it so, you must apply a specific selector to find it with selenium. – Zzirconium Apr 06 '20 at 08:15
  • @zzirconium hello I went a head and read up on the iframe subject, and im writing to confirm that the element is not within an iframe – jthesimple Apr 07 '20 at 02:14
  • We would need the complete dom path of your element to help you on the xpath. The shortest way to fond it would be the id, though. Make sure this id has been given solely to this element. You are using ** characters to surround your id, this is only accepted since HTML5 so make sure your page does comply with HTmL5, otherwise as a test, give this element an id that is random (it will ensure to be unique) lastly, avoid finding elements with the name only, as name attribute can be shared among many elements. – Zzirconium Apr 07 '20 at 06:38

0 Answers0