I've very new to Python and Selenium and I think I need to use the Assert command to verify a text field has what I typed in via Selenium.
I've searched for an hour and can't find the answer.
Here is my code:
from selenium import webdriver from selenium.webdriver.common.action_chains import ActionChains as AC from selenium.webdriver.common.by import By from selenium.webdriver.common.keys import Keys from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import Select, WebDriverWaitdriver = webdriver.Ie()
driver.get(“https://bie.farmersinsurance.com/”)
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, “/html/body/div/form/table/tbody/tr[5]/td/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr[1]/td[1]/input”))).send_keys(“tess893”)
element = driver.find_element_by_xpath(“/html/body/div/form/table/tbody/tr[5]/td/table/tbody/tr/td/table/tbody/tr[2]/td/table/tbody/tr[1]/td[1]/input”)
assert element.text == “tess893”
Here are my results:
Traceback (most recent call last):
File “c:\Users\uswarv41.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\ptvsd_launcher.py”, line 45, in <module>
main(ptvsdArgs)
File “c:\Users\uswarv41.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd_main_.py”, line 265, in main
wait=args.wait)
File “c:\Users\uswarv41.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd_main_.py”, line 256, in handle_args
run_main(addr, name, kind, *extra, **kwargs)
File “c:\Users\uswarv41.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd_local.py”, line 52, in run_main
runner(addr, name, kind == ‘module’, *extra, **kwargs)
File “c:\Users\uswarv41.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd\runner.py”, line 32, in run
set_trace=False)
File “c:\Users\uswarv41.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd_vendored\pydevd\pydevd.py”, line 1283, in run
return self._exec(is_module, entry_point_fn, module_name, file, globals, locals)
File “c:\Users\uswarv41.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd_vendored\pydevd\pydevd.py”, line 1290, in _exec
pydev_imports.execfile(file, globals, locals) # execute the script
File “c:\Users\uswarv41.vscode\extensions\ms-python.python-2018.12.1\pythonFiles\lib\python\ptvsd_vendored\pydevd_pydev_imps_pydev_execfile.py”, line 25, in execfile
exec(compile(contents+“\n”, file, ‘exec’), glob, loc)
File “c:_TMP\Test2.py”, line 18, in <module>
assert element.text == “tess893”
AssertionError
I don’t know why am I getting an AssertionError. Based on what I read, it should not throw any errors.
#python #selenium