Search code examples
pythonseleniumreddit

I am having trouble clicking the signup button on a reddit sign up page with selenium using python


I am trying to submit a form to create a new reddit account using selenium at https://www.reddit.com/reddits/login/ . I am new to using selenium and web scraping in general and need some help selecting and ultimately clicking the sign up button on this webpage after all the details have been entered in. I have tried to select it using

submit = browser.find_element(By.CSS_SELECTOR("//*[@id="register form"]/div[7]/button")).text

along with trying to grab it through its xpath which is

//*[@id="register-form"]/div[7]/button

but am having no luck. The farthest I am able to get is having it say a 'str' object is not callable using Selenium through Python as an error message or it will say element not found. Any help would or guidance in the right direction would be greatly appreciated.

I am able to enter in all fields of data and beat the re-captcha that pops up also and be entirely good to go except for this sign up button. I am not familiar with this much so I am not sure why any of the responses answers worked when I tried them. I am not sure if it is something about the button or if its just how the page is setup or if its needing to run some javascript with the button click. I am not sure why this button cannot be clicked.

To solve the re-captcha I load another webpage and delete it to get back to this one not sure if this is relevant or not.

Picture of the Button I am trying to click on with selenium

Sign Up Button Picture

SOLVED: All of these solution below work for accessing the button. My mistake was switching to a different tab and not properly switching back. So I was trying to click an element on an old tab not the main sign in page. Once the focus was shifted back to that page the element was found and clicked!


Solution

  • The CSS Selector for that submit button would be:

    "#register-form button"

    You can verify from the console of a web browser by calling:

    document.querySelector("#register-form button")