7

I am new to selenium. I am trying to set my username in in gmail browser by using python2.6.

import unittest
from selenium import webdriver;
from selenium import WebElement;
driver = webdriver.Ie();
driver.get("http://www.gmail.com");

WebElement uname = driver.find_element(by=By,id("Username:"));

uname.sendKeys("chakry.gosetty");

With the above code I am getting

WebElement uname= driver.find_element(by=By,id("Username:"));
SyntaxError : Invalid syntax.

Please help me.

Rgds, G.Chakravarthy

nmc
  • 8,724
  • 5
  • 36
  • 68

3 Answers3

16

How about...

import unittest
from selenium import webdriver

driver = webdriver.Ie()
driver.get('http://www.gmail.com')

driver.find_element_by_id('Email').send_keys('chakry.gosetty')
  • you don't need semicolons as line terminators in python :)
  • also, the username field ID is actually Email not Username:
Isaac
  • 9,372
  • 4
  • 28
  • 31
7

A guess: Apart from the other obvious syntax errors, you don't import By. How about this:

from selenium.webdriver.common.by import By
...
uname = driver.find_element(By.ID,value="...")
Ruggiero Spearman
  • 6,735
  • 5
  • 26
  • 37
0

Isaac's answer is correct with a small modification. The email field on gmail is an input type field that does not have a reliable id. I would go with below syntax to identify that field.

driver.find_element_by_css_selector('input[type='email']')

Since your question was about how to find an element using ID the answer is

driver.find_element_by_id("idLocatorValue")