Skip to content

Instantly share code, notes, and snippets.

@abhianair
Last active October 24, 2019 04:54
Show Gist options
  • Save abhianair/0f9d26fbaa1fd183c7e89a5c4f07dc89 to your computer and use it in GitHub Desktop.
Save abhianair/0f9d26fbaa1fd183c7e89a5c4f07dc89 to your computer and use it in GitHub Desktop.
Adding checkout fields automatically using python selenium
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
print("Enter wp username")
user = str(input())
print("Enter wp password")
passw = str(input())
print("Enter field numbers")
num = int(input())
driver = webdriver.Chrome('chromedriver')
driver.get("http://localhost/wordpress/wp-admin/")
user_name = driver.find_element_by_id("user_login")
password = driver.find_element_by_id("user_pass")
# login
user_name.clear()
user_name.send_keys(user)
password.clear()
password.send_keys(passw)
driver.find_element_by_id("wp-submit").click()
# checkout home
driver.get('http://localhost/wordpress/wp-admin/admin.php?page=th_checkout_field_editor_pro')
i = 1
p = 5
for x in range(num):
num = str(i)
driver.find_element_by_xpath('//*[@id="thwcfe_checkout_fields"]/thead/tr[1]/th[1]/button[1]').click()
driver.find_element_by_xpath('//*[@id="thwcfe-tab-general_new"]/table[1]/tbody/tr[2]/td[3]/input').send_keys('field_price'+num)
driver.find_element_by_xpath('//*[@id="thwcfe-tab-general_new"]/table[2]/tbody/tr[1]/td[3]/input').send_keys('Price'+num)
driver.find_element_by_xpath('//*[@id="thwcfe-tab-general_new"]/table[2]/tbody/tr[6]/td[3]/input[1]').send_keys(p)
driver.find_element_by_xpath('/html/body/div[7]/div[3]/div/button[2]').click()
p = p + 10
i = i + 1
driver.find_element_by_xpath('//*[@id="thwcfe_checkout_fields"]/tfoot/tr[2]/th[2]/input[1]').click()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment