I am having trouble, as everything I have tried does not work. I have tried using python requests. Unfortunately, this does not work because the form is loaded 1 or so seconds after the webpage, making a post request impossible. Grudgingly, I switched to selenium. However, I cannot locate elements by xpath, id, or class because they are all loaded dynamically and randomized each time the web page loads. Is there any other way to possibly sign up?
Requests: When attempting to pass a post request. It fails because the page/form hasn't loaded yet (see URL in title)
m = {}
m["fullName"] = "test"
requests.post(url, data=m)
Selenium Attempt: Does not work because ids/class names/ etc are randomized each time.
email_field = driver.find_element_by_id("f2e3acfde5540d")
name_field = driver.find_element_by_id("f15a1d5523914b")
username_field = driver.find_element_by_id("ff9c874585158")
password_field = driver.find_element_by_id("f233cff115218c8")
Here is an example, how to login/sign up to the instagram via Selenium using xpath selectors. I wrote this with a selenium wrapper Elementium for less code. But, you can use the same selectors for your code.
from elementium.drivers.se import SeElements
from selenium import webdriver
browser = webdriver.Chrome()
browser.get('https://www.instagram.com/accounts/login/?hl=en')
se = SeElements(browser)
se.xpath('//input[@name="username"]', wait=True, ttl=2).clear().write('username')
se.xpath('//input[@type="password"]', wait=True, ttl=2).clear().write('password')
se.xpath('//button[contains(text(), "Log in")]', wait=True, ttl=2).click()
assert se.xpath('//a[text()="Profile"]', wait=True, ttl=2), 'User was not logged in.'
The same to Sign Up:
browser.get('https://www.instagram.com/?hl=en')
se = SeElements(browser)
se.xpath('//input[@name="emailOrPhone"]', wait=True, ttl=2).clear().write('366656')
se.xpath('//input[@name="fullName"]', wait=True, ttl=2).clear().write('Alex')
se.xpath('//input[@name="username"]', wait=True, ttl=2).clear().write('Alex')
se.xpath('//input[@name="password"]', wait=True, ttl=2).clear().write('password')
se.xpath('//button[contains(text(), "Sign up")]', wait=True, ttl=2).click()