Select a specific input box from multiple boxes which have the same HTML code

Viewed 31

I am trying to insert a container number in the first input box but the page has 3 and all have the same HTML code. How can I select only the first box? I tried a couple of things but I always get an error:

NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@type='text'and @class='inputmember'][1]"}

HTML code:

<div id="cnfield1">

    <input name="numbers" type="text" class="inputmember" value="" 
    style="width:130px;ime-mode:disabled;text-transform:uppercase;" onkeydown="if 
    (window.event.keyCode == 13) { validateSearchFormCTP(); }"> 

    <input name="numbers" type="text" class="inputmember" value="" 
    style="width:130px;ime-mode:disabled;text-transform:uppercase;" onkeydown="if 
    (window.event.keyCode == 13) { validateSearchFormCTP(); }"> 

    <input name="numbers" type="text" class="inputmember" value="" 
    style="width:130px;ime-mode:disabled;text-transform:uppercase;" onkeydown="if 
    (window.event.keyCode == 13) { validateSearchFormCTP(); }"> 

    <a class="new_btn02" href="javascript:makeField('cn');">+ADD</a>
</div>

<td class="text_R">
    <a class="new_btn03" id="resetBtn" href="#">Reset</a>
    <a class="new_btn08" id="inquiryBtn" href="#">Inquiry</a>
</td>

Python code:

Lst=['HDMU2795525']

if i == 'HYUNDAI':
    #HYUNDAI
    driver.get('https://www.hmm21.com/cms/business/ebiz/trackTrace/trackTrace/index')

    #element= WebDriverWait(driver, 120).until(
    expect.visibility_of_element_located((By.XPATH, "//input[@class='inputmember']")))

    for j in Lst:
        
        #Insert container number

        driver.find_element_by_xpath("//input[@type='text'and @class='inputmember'][1]").click()
        driver.find_element_by_xpath("//input[@type='text'and @class='inputmember'][1]").send_keys(j)
               
        #Search
        driver.find_element_by_xpath("//a[@id='inquiryBtn']").click()        
1 Answers

Form is located inside an iframe so you need to switch to that frame before filling the form:

driver.switch_to_frame('_frame1')
driver.find_element_by_xpath("//input[@type='text' and @class='inputmember'][1]")
Related