1

I am having serious difficulty filling in text boxes on this website. The element is type="text". It keeps returning as AttributeError: 'NoneType'.

I used a try clause to see if it was actually being clicked on, and it is not erring out. In addition, the textbox is selected and when I leave it as my front window, I can type in the text box without clicking anything after the error occurs.

I tried extending the pause before the click by 1 minute to no effect.

I tried selecting by xpath, same results.

I tried clicking the object, pausing 10 seconds, and clicking the object again. Nothing.

my code:

def Search(driver,productID):
    print "Initiate Search"

    #Fill in current product ID
    #/html/body/table[3]/tbody/tr/td/table/tbody/tr/td[2]/div[2]/form/table/tbody/tr/td/input

    try: inputElement = driver.find_element_by_name("CategoryName").click()
    except: print "could not click"
    print "Clicked Product ID"

    time.sleep(5)
    inputElement.send_keys(str(productID))  ##Line 105 - Errors out here

Error

Traceback (most recent call last):
  File "/Users/ME/Documents/PYTHON/Creating Static Attributes/StaticWAttributes_1.py", line 246, in <module>
    Search(driver,productID)
  File "/Users/ME/Documents/PYTHON/Creating Static Attributes/StaticWAttributes_1.py", line 105, in Search
    inputElement.send_keys(str(productID))
  AttributeError: 'NoneType' object has no attribute 'send_keys'

Last Output Print Statement:

Initiate Search
Clicked Product ID

HTML:

  <table cellSpacing="0" cellPadding="0" border="0">
        <tr>
          <td class="actionrow">Search Products by  
          <select name="categorytype">
                        <option selected value="name">Product Name or Description</option>
                        <option  value="catid">Product ID</option>
                  </select> <input type="text" name="CategoryName" value="" size="20"><? <<-- I AM TRYING TO CLICK THIS ?>
                  &nbsp;in&nbsp;
                  <select name="ddlproductType" ID="Select2">
                    <option selected value="100">All</option>
                        <option  value="1">Versioned</option>

                            <option  value="7">Variable</option>

                        <option  value="5">Static with Attributes</option>
            <option  value="11">PowerPoint</option>
                  </select>&nbsp;
                <input type="submit" value="Go" name="action" onClick="javascript:resetAll();"> 
          </td>
        </tr>
  </table>

1 Answer 1

9

Your problem is here:

    try: inputElement = driver.find_element_by_name("CategoryName").click()

I'm not sure what inputElement is in the case of python, but I'm guessing it's still a null. I don't think click() returns anything.

If you change it to this, it should work:

try: inputElement = driver.find_element_by_name("CategoryName")
    inputElement.click()
Sign up to request clarification or add additional context in comments.

2 Comments

Wow, that one flew right over my head. Much appreciated. I can't accept your answer for a couple more minutes, but it's coming.
Comment: Python often does this, by design, to discourage the building of very complex expressions. E.g. you're not allowed to say if ((x = findelement()) != Null), sorting a list in place returns Null, etc. Looks like Selenium is adopting the same style.

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.