-4

I'm new python (programming). Currently working on a project to fill up forms using selenium and python.

So for everything seems okay. I successfully installed python 3.6, selenium on pycharm and chrome drive on my windows.

I try to open a website and fill the form using the script. The script opens the site but couldn't put the texts in the form.

I have been browsing stack overflow and googling for hours and anything doesn't work.

It shows error regarding sendkeys.

Here's the full code

from selenium import webdriver

from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import time

# Replace below path with the absolute path
# to chromedriver in your computer
driver = webdriver.Chrome('C:\\Users\public\chromedriver.exe')


# Go to your page url
driver.get('https://www.website.com/')

# Get button you are going to click by its id ( also you could us find_element_by_css_selector to get element by css selector)
button_element = driver.find_element_by_class_name('signup_email_link')
button_element.click()

input_element = driver.find_element_by_name("first_name")
input_element.sendkeys(ram)

Here's the error code,

C:\Users\user\AppData\Local\Programs\Python\Python36-32\python.exe "C:/Users/user/PycharmProjects/My Projects/My scripts automate.py"
Traceback (most recent call last):
  File "C:/Users/user/PycharmProjects/My Projects/My scripts automate.py", line 22, in <module>
    input_element.sendkeys(ram)
AttributeError: 'WebElement' object has no attribute 'sendkeys'

Process finished with exit code 1

I even tried to replace the input_element with web_element but error continuous.

I use latest Python 3.6 version on pycharm.

Joel
  • 1
  • 3
  • 5
    Possible duplicate of [Python Selenium - AttributeError : WebElement object has no attribute sendKeys](http://stackoverflow.com/questions/38521136/python-selenium-attributeerror-webelement-object-has-no-attribute-sendkeys) – Sasha Apr 28 '17 at 13:07
  • No, it's different question bro – Joel Apr 28 '17 at 13:09
  • Does send_keys not work? – Sasha Apr 28 '17 at 13:11
  • No, bro it doesn't – Joel Apr 28 '17 at 13:15
  • 1
    I've read the other parts.. It does work, you have a different error because of the undefined variable "ram". So therefore your original question was a duplicate.. – Sasha Apr 28 '17 at 13:15
  • Okay bro I will define ram. If it doesn't work. I will come again. – Joel Apr 28 '17 at 13:17

2 Answers2

2

Use

input_element.send_keys(ram)

instead of

input_element.sendkeys(ram)
Cov
  • 561
  • 5
  • 20
  • Thanks Sithling. but not working. Here's the error, C:\Users\user\AppData\Local\Programs\Python\Python36-32\python.exe "C:/Users/user/PycharmProjects/My Projects/My scripts automate.py" Traceback (most recent call last): File "C:/Users/user/PycharmProjects/My Projects/My scripts automate.py", line 22, in input_element.send_keys(ram) NameError: name 'ram' is not defined Process finished with exit code 1 – Joel Apr 28 '17 at 13:13
  • 1
    @Joel you need to define `ram`, looking at your code there is no mention of the `ram` variable. – Cov Apr 28 '17 at 13:14
2

It should be input_element.send_keys(ram).

List of methods here.

mazjin
  • 80
  • 2
  • 10
  • Thanks for your answer Mazjin. – Joel Apr 28 '17 at 13:11
  • Here's the error, C:\Users\user\AppData\Local\Programs\Python\Python36-32\python.exe "C:/Users/user/PycharmProjects/My Projects/My scripts automate.py" Traceback (most recent call last): File "C:/Users/user/PycharmProjects/My Projects/My scripts automate.py", line 22, in input_element.send_keys(ram) NameError: name 'ram' is not defined Process finished with exit code 1 – Joel Apr 28 '17 at 13:12
  • 1
    With the underscore included? Does it give a different error message? – mazjin Apr 28 '17 at 13:13
  • 1
    @Joel you need to define `ram`, looking at your code there is no mention of the `ram` variable. – Cov Apr 28 '17 at 13:13
  • Ah, well you just need to set `ram` to a string containing whichever characters you need to send, or replace it with said string, ie. `ram='some string' input_element.ssend_keys(ram)` or `input_element.send_keys('some string'` – mazjin Apr 28 '17 at 13:15
  • but that's a name – Joel Apr 28 '17 at 13:15
  • where is ram coming from? where do you initialise this? – Sasha Apr 28 '17 at 13:16
  • If you want it to literally send the string 'ram', you need to tell it that it's a string using quotation marks like I've just done. – mazjin Apr 28 '17 at 13:17
  • I'm new to programming. I never defined 'ram'. I will define to see whether works or not. Thanks guys. – Joel Apr 28 '17 at 13:20
  • No worries, make sure to accept @ProNinjaCat's answer above. – mazjin Apr 28 '17 at 13:30
  • @mazjin i didn't make an answer for it, so best to accept yours i suppose – Sasha Apr 28 '17 at 13:50