3
title='this is the title'

I want to locate with python/selenium, within a web page, this line:

<input id="subject" name="subject" maxlength="50" value="" class="nude error" type="text">

I use this code with python-selenium (under Debian):

title = driver.find_element_by_id("subject").clear()
title.send_keys(title) 

I got the following error:

Traceback (most recent call last):

  File "./basic0", line 49, in <module>
titre.send_keys(title)

AttributeError: 'NoneType' object has no attribute 'send_keys'

note:when the script stops because of this error, the mouse cursor is at the right at place within the web page; but I cannot find a way to send_keys to fill in the input

I also tried:

title = driver.find_element_by_xpath("div[contains(text(),'subject')]")

title = driver.find_element_by_xpath("//form[input/@id='subject']")

title = driver.find_element_by_xpath("//form[input[@name='subject']")

but it does not work; furthermore the mouse cursor is not at the right place.

then I tried a later selenium version:

I completly purge python-selenium package under Debian (which is selenium v. 2.53) then

pip install selenium==3.3.1

This time, when I launch the script it says that geckodriver is missing: so,

wget https://github.com/mozilla/geckodriver/releases/download/v0.23.0/geckodriver-v0.23.0-linux32.tar.gz

tar -xvzf geckodriver-v0.23.0-linux32.tar.gz

chmod 755 geckodriver (I also tried 777)

mv geckodriver /usr/local/bin/ (so it's in my PATH)

now when I launch the script, here is the error message I got:

Traceback (most recent call last):

  File "./basic0", line 13, in <module>
driver = webdriver.Firefox()

  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/firefox/webdriver.py", line 155, in __init__
keep_alive=True)

  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 92, in __init__
self.start_session(desired_capabilities, browser_profile)

  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 179, in start_session
response = self.execute(Command.NEW_SESSION, capabilities)

  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/webdriver.py", line 238, in execute
self.error_handler.check_response(response)

  File "/usr/local/lib/python2.7/dist-packages/selenium/webdriver/remote/errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)

selenium.common.exceptions.WebDriverException: Message: connection refuse

firefox window pops-up, and then shutdown when the script stops

2

3 Answers 3

3

You've assigned method call (clear()) which returns None to title variable while you need to define WebElement and call methods subsequently as

title = driver.find_element_by_id("subject")
title.clear()
title.send_keys("title")
Sign up to request clarification or add additional context in comments.

2 Comments

I tried your solution and first got: "AttributeError: 'WebDriver' object has no attribute 'clear' ". I then removed title.clear(); it worked but filled the input in with 'title' instead of the variable content. I then tried driver.send_keys(title): it was ok. Now just wondering why clear() did not work. Thank you indeed!
@achille , I guess you tried driver.clear() instead of title.clear() (title should be object of type WebElement)
1

if you are able to click in the text box but you are unable to type in there because send_keys is not working and you are in hurry or you want to just click without selecting any element then:

please install this module by typing pip install pyautogui

import pyautogui


#use this line to type something 
pyautogui.typewrite('Anything you wanna type')

#use this line to press any key
pyautogui.press("esc")

[here][1] is the list of keys you can press
Note : If you are going to minimize the windows pyautogui will start typing at the place you currently clicking or when the pyautogui.typewite() is executing and you are on other pages it will start typing on the page you are in rather then typing on webpage.   

Comments

1

use this in python. it is working fine

    action = ActionChains(driver)
    EnterMobileNumber = self.driver.find_element(AppiumBy.ID, 'mention locator here')
    action.move_to_element(EnterMobileNumber).click(EnterMobileNumber).send_keys("8888888888").perform()

Comments

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.