Home > Back-end >  Python - Expanding a group using selenium
Python - Expanding a group using selenium

Time:02-10

I'm new to python and I'm trying to automate a few tasks.

My issue is when I log in to my server I need to expand the group and select the form inside the group, I'm using find_element By Xpath and ID and keep getting this error "Unable to locate element:", I tried to use sleep or WebDriverWait but didn't work.

My element code in image now (the arrow):

When I open it manual the aria-expanded changed to ="true"

My group code:

Main group

Forms


The website login details (dummy server): server: https://new2001.surveycto.com/ user: [email protected] password: Stackoverflow_example

CodePudding user response:

driver.get(" https://new2001.surveycto.com/")
time.sleep(5)
driver.find_element(By.ID, "login-username").send_keys("[email protected]")
driver.find_element(By.XPATH, "//button[text()='Next']").click()
time.sleep(1)
driver.find_element(By.ID, "login-password").send_keys("Stackoverflow_example")
time.sleep(1)
driver.find_element(By.XPATH, "//button[text()='Log in']").click()
time.sleep(10)
ActionChains(driver).move_to_element(driver.find_element(By.XPATH, "(//*[@data-form-field-id='foundation'])[1]")).perform()
time.sleep(1)
driver.find_element(By.XPATH, "(//*[@data-form-field-id='foundation'])[1]//button[@data-original-title='Add form, group or dataset']").click()
time.sleep(1)
driver.find_element(By.XPATH, "(//*[@data-form-field-id='foundation'])[1]//div[@class='primary-actions']//a[contains(@data-original-title, 'start from scratch')]").click()
time.sleep(5)
x = driver.find_element(By.XPATH, "//form[@method='post']//h3").text
print(x)
driver.save_screenshot('snapshot.png')
driver.quit()

This code logs in to the website with the credentials and then clicks on the icon of the Foundation form, and after the expansion occurs, it clicks on the Start New Form button, and just to verify for you, it takes the snapshot of the screen and extracts the form header.

Output:

Start new form - Step 1

Process finished with exit code 0

Form Snapshot

  • Related