硒无法通过ID,XPath或名称找到元素

时间:2020-04-05 23:24:50

标签: python selenium automation webdriver sendkeys

我无法通过ID,名称或xpath查找元素。我的代码如下:

#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')

我正在尝试选择“ txtQuantity_Dec” ID,请参见以下代码:

<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();">

这是我在运行代码时遇到的错误:

消息:没有这样的元素:无法找到元素:{“ method”:“ css选择器”,“ selector”:“ [name =” txtQuantity_DEC“]”}

我尝试通过id,name和xpath进行操作。知道为什么硒找不到我要选择的文本框吗?

0 个答案:

没有答案