1

im trying to write a code to automatically create a gmail using selenium. the item im trying to find is the firstname input in the url below:

https://accounts.google.com/signup/v2/webcreateaccount?service=mail&continue=https%3A%2F%2Fmail.google.com%2Fmail%2F&flowName=GlifWebSignIn&flowEntry=SignUp

i used wait but it returns a TimeoutException error. also, say i want to use implicit wait, how can i do that?

thanks

class BotCreator:

    def __init__(self, firstname, lastname):
        self.firstname = firstname
        self.lastname = lastname
        self.driver = webdriver.Firefox(executable_path=r'A:\Python Projects\The InstaBOT/geckodriver')

    def shutdown(self):
        self.driver.close

    def gmail_creator(self, n_bots):
        for n in range(n_bots):
            global email
            email = {}
            driver = self.driver
            wait = WebDriverWait(driver, 10)
            driver.get('https://www.google.com/intl/en-GB/gmail/about/')
            driver.find_element_by_xpath('//a[@title="Create an account"]').click()
            wait.until(ec.new_window_is_opened(driver.window_handles))
            after = driver.window_handles[1]
            driver.switch_to.window(after)
            element = wait.until(ec.element_to_be_clickable((By.XPATH, '//input[@id="firstName"]')))
            element.send_keys('awsd')

        return email

gmail_t = BotCreator('John', 'Hoffinsky')
gmail_t.gmail_creator(1)

3
  • Can you confirm that once you click on create account are you on same page or it opens a new window? Commented Sep 24, 2019 at 14:32
  • it opens a new tap in firefox. since the new tab is the one that is open, i figured its not the problem. is it? Commented Sep 24, 2019 at 14:39
  • Yes you need to switch to that window to access the element.I have added the code. Commented Sep 24, 2019 at 14:41

3 Answers 3

2

There are actually several (4) elements with the same XPath on that page. Try to use a specific one with following XPath:

(//a[@title="Create an account"])[1]

Your XPath returns 4 elements with the Chrome extension ChroPath.


Regarding your question about implicit wait: You are already using implicit wait. The implicit wait setting tells Selenium to poll for the specified amount of time until an element is available. You can change the timeout if needed:

driver.implicitly_wait(15)

This link could be helpful.

Sign up to request clarification or add additional context in comments.

5 Comments

thanks for answering. im trying to input my firstname not to create an account. i have already clicked on the create an account
also, the wait in my code, webdriverwait; whats the difference of it with implicitwait
Implicit wait does not need any additional code. It is used always. Explicit wait like in your code is an additional wait. You use it for one specific action.
didn't know that. so i just change the time of the waiting. i cant still locate the element though. i also updated the code.
element = wait.until(ec.element_to_be_clickable((... @KunduK suggested that i remove the for loop and now it works but i dont know why!
1

Once you click on the create Account button it opens a new window for user details.You need to Switch to that window to access the element.Try below code.

wait = WebDriverWait(driver, 10)
driver.get('https://www.google.com/intl/en-GB/gmail/about/')
driver.find_element_by_xpath('//a[@title="Create an account"]').click()
wait.until(ec.new_window_is_opened(driver.window_handles))
after=driver.window_handles[1]
driver.switch_to.window(after)
element = wait.until(ec.element_to_be_clickable((By.XPATH, '//input[@id="firstName"]')))
element.send_keys('awsd')

Browser snapshot:

enter image description here

5 Comments

still gives the error: selenium.common.exceptions.TimeoutException: Message:
yeah i did. im really confused too
@Johnsmith : whats the for loop?
im using the loop to be able to create more than 1 gmail. n_bots is the number of gmails
Just try to create single account first with given code and check if you get any error?
0

Is always good to use ID than XPath/CSS

Example

driver.find_element_by_id("FirstName").send_keys("email")

1 Comment

this link might help you .. screenster.io/…,

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.