【发布时间】:2021-04-16 06:28:00
【问题描述】:
所以我想更新我的配置文件下的所有现有值,在执行过程中我可以看到新值正在输入到文本字段中,但是一旦我的脚本执行单击保存按钮,它就会恢复到以前的状态价值。我很困惑有人可以帮助我吗:)拜托..
谢谢
这是我的脚本
driver.find_element_by_link_text('SIGN IN').click()
time.sleep(1)
#enter credentials
welcome = driver.find_element_by_xpath("//h1[contains(text(),'Welcome back!')]")
user_email = driver.find_element_by_name('email').send_keys("")
user_pass = driver.find_element_by_name('password').send_keys("")
driver.find_element_by_link_text('SIGN IN').click()
print(welcome.text)
print(driver.title)
print("sign in passed")
wait = WebDriverWait(driver, 5)
profile_id = wait.until(EC.presence_of_element_located((By.XPATH, "//header/div[1]/div[1]/img[1]")))
profile_id.click()
time.sleep(3)
prof_ele = driver.find_element_by_xpath("//a[contains(text(),'Edit Profile')]")
log_out = driver.find_element_by_xpath("//button[contains(text(),'Logout')]")
print(prof_ele.text)
print(log_out.text)
prof_ele.click()
#edit profile
#Name
driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[2]/div[1]/div[1]/*[1]").click()
name_ele = driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[2]/div[1]/div[1]/input[1]")
driver.execute_script("arguments[0].value=arguments[1]", name_ele, "My name is John")
# Occupation
driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[4]/div[1]/div[1]/*[1]").click()
occupation_ele = driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[4]/div[1]/div[1]/input[1]")
driver.execute_script("arguments[0].value=arguments[1]", occupation_ele, "QA analyst")
#about me
driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[4]/div[2]/div[1]/*[1]").click()
bio_ele = driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[4]/div[2]/div[1]/input[1]")
driver.execute_script("arguments[0].value=arguments[1]", bio_ele, "Nothing to say about me")
#birthday
driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[4]/div[3]/div[1]/*[1]").click()
birthday = driver.find_element_by_name("birthday")
driver.execute_script("arguments[0].value=arguments[1]", birthday, "1993-06-20")
#web
driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[4]/div[4]/div[1]/*[1]").click()
web_ele = driver.find_element_by_name("website")
driver.execute_script("arguments[0].value=arguments[1]", web_ele, "www.instagram.com")
#hobbies
driver.find_element_by_xpath("//body/div[@id='root']/div[2]/div[2]/form[1]/div[2]/div[4]/div[5]/div[1]/*[1]").click()
hobbies = driver.find_element_by_name("interests")
driver.execute_script("arguments[0].value=arguments[1]", hobbies, "Run, Eat, Photography")
time.sleep(3)
driver.find_element_by_xpath("//button[contains(text(),'Save')]").click()
alert = WebDriverWait(driver, 10).until(EC.alert_is_present())
print(alert.text)
alert.accept()
time.sleep(5)
print(name_ele.get_attribute('value'))
print(occupation_ele.get_attribute('value'))
print(bio_ele.get_attribute('value'))
print(birthday.get_attribute('value'))
print(hobbies.get_attribute('value'))
print("All tests passed!")
【问题讨论】:
-
页面有链接吗?
-
尽量避免电子邮件共享
-
实际上它只是一封测试电子邮件:D 但我删除了屏幕截图和脚本:D