I am trying to learn Selenium. I am using Python 2.7. Phantom JS - 2.1.1.
Background - The script is trying to enter data into the controls. The script is able to catch hold of controls. However the data from older execution is retained.
SCREENSHOT
ADDITIONAL DETAILS As you can see in the EMAIL box, the last execution data is retained. In Checkboxes I clicked the same checkbox and then it appears unselected. As for Name field - I used clear() method and the earlier data was cleared. Same method is not working for email text box.
Please find the python code snippet -
import time,traceback
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import Select
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
COMPANY_NAME = 'AHXJ OF KCH'
FIRST_NAME = 'Bill'
LAST_NAME = 'CLINTON'
EMAIL = 'bill.clinton@whitehouse.com'
driver = webdriver.PhantomJS()
driver.delete_all_cookies()
driver.implicitly_wait(10)
driver.set_window_size(1120, 550)
try:
driver.get("https://username:password@url/")
select_state = Select(driver.find_element_by_id('state_abbrev'))
select_state.select_by_visible_text('Arizona')
time.sleep(5)
select_business_segment = Select(driver.find_element_by_id('business_segment_id'))
select_business_segment.select_by_visible_text('IT/Technology')
time.sleep(5)
select_business_type = Select(driver.find_element_by_id('business_type_id'))
select_business_type.select_by_visible_text('Application Development')
driver.save_screenshot(COMPANY_NAME+ '_home_page_screenshot.png')
driver.find_element_by_xpath('//*[@id="chubb_commercial_entry_form"]/div/button').click()
time.sleep(10)
#wait = WebDriverWait(driver, 10).until( EC.element_to_be_clickable((By.ID, 'product_codes__bop')))
driver.find_element_by_xpath('//*[@id="field_for_product_codes__bop"]/label').click()
comp_name = driver.find_element_by_id('business_name')
comp_name.clear()
comp_name.send_keys(COMPANY_NAME)
email = driver.find_element_by_id('email')
email.clear()
email.send_keys(EMAIL)
driver.save_screenshot(COMPANY_NAME+ '_business_info_screenshot.png')
driver.find_element_by_xpath('//*[@id="commercial-app"]/div/div[2]/div[2]/div/div[2]/form/div[1]/div/div/button').click()
time.sleep(10)
...
except Exception,e:
print e
driver.save_screenshot('error_screenshot.png')
traceback.print_exc()
finally:
driver.quit()
EDIT 2 - ADDITIONAL INFORMATION
- The site is made using ReactJS. Since I am zero in React, I have no idea how it works. I thought of changing the value of HTML input attribute, but on inspecting I found that it is always true
- I dont think the problem is with checkbox, I feel it is the problem the way I am executing Python and Selenium because Data is saved across page and across script execution
- Not sure, if this point is important - I am developing in c9.io
image - before click
image - after click