1

After passing the value in the NID textbox, new elements are displayed on the web page. such as Firstname :

for row in rows:
    y = driver.find_element_by_id('NId')
    y.send_keys(row)
    driver.find_element_by_xpath("//body").click()
    
    a1 = driver.find_element_by_id('Firstname')
    firstname = a1.get_attribute('value')

After executing the command to set a1, I get an error:

Exception has occurred: NoSuchElementException Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="Firstname"]"}

Textbox NId :

<input class="form-control ltr left text-box single-line" data-val="true" data-val-regex="It is 10 numbers" data-val-regex-pattern="^[0-9]{10}$" data-val-required="*required" id="NId" maxlength="10" name="NId" onblur="LoadInfo()" type="text" value="">

Textobx Name (fill and appear after enter the NId) :

<form action="/Employees/Manager/SavePerson" data-ajax="true" data-ajax-begin="onpostcreatebegin" data-ajax-complete="onpostcreatecomplete" data-ajax-loading="#ajaxloading" data-ajax-method="post" data-ajax-mode="replace" data-ajax-update="#result" id="form0" method="post" novalidate="novalidate"><input name="__RequestVerificationToken" type="hidden" value="asdxBadsP7CpS53654as6dadH3865asdadKhjasdad">        <input type="hidden" name="empId" id="empid" value="0">
    <div class="panel panel-info">
        <div class="panel-body">
            <input data-val="true" data-val-regex="It is 10 numbers" data-val-regex-pattern="^[0-9]{10}$" data-val-required="*required" id="NId" name="NId" type="hidden" value="1234567890">
            <input data-val="true" data-val-number="The field PersonId must be a number." data-val-required="The PersonId field is required." id="PersonId" name="PersonId" type="hidden" value="254102232">
            <input data-val="true" data-val-required="The GuidId field is required." id="GuidId" name="GuidId" type="hidden" value="665xs6asd-cxc2-wq56-8888-30654998b166">
            <div class="form-group">
                <div class="col-md-4">
                    <input class="form-control text-box single-line" data-val="true" data-val-regex="enter the name." data-val-regex-pattern="^[\u0600-\u06ff\s]+$|[\u0750-\u077f\s]+$|[\ufb50-\ufc3f\s]+$|[\ufe70-\ufefc\s]+$|[\u06cc\s]+$|[\u067e\s]+$|[\u06af\s]$|[\u0691\s]+$|^$" data-val-required="*required" id="Firstname" name="Firstname" type="text" value="jack">
                    <span class="field-validation-valid text-danger" data-valmsg-for="Firstname" data-valmsg-replace="true"></span>
                </div>
            </div>

        </div>
    </div>  
</form>
3
  • 1
    Please post the HTML. Commented Sep 18, 2021 at 16:26
  • Can you try this.. element = WebDriverWait(driver, 10).until( EC.visibility_of_element_located((By.ID, "Firstname")) firstname = element.get_attribute('value') Commented Sep 18, 2021 at 16:47
  • That's true. It worked. thanks Commented Sep 18, 2021 at 16:53

2 Answers 2

1

I guess element is taking time to be visible so please use explict wait.

Code:

element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "Firstname")) 
firstname = element.get_attribute('value')
Sign up to request clarification or add additional context in comments.

Comments

0
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
wait = WebDriverWait(driver,100)

locate = wait.until(EC.presence_of_element_located((By.XPATH,'your_xpath_here')))
locate_value = locate.text

1 Comment

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.