Skip to content

Instantly share code, notes, and snippets.

@xros
Forked from devhero/selenium_set_attribute.py
Created March 25, 2018 21:33
Show Gist options
  • Save xros/703066ac95d37596e0c1557e87c509a8 to your computer and use it in GitHub Desktop.
Save xros/703066ac95d37596e0c1557e87c509a8 to your computer and use it in GitHub Desktop.
# retrieve webelement
input = driver.find_element_by_xpath("//*[@name='fieldname']")
# set attribute from js script referencing webelement found in python code
driver.execute_script("arguments[0].setAttribute('value', 'new value!')", input);
# or
driver.execute_script("arguments[0].setAttribute('value', arguments[1])", input, 'new value!');
# Code for File Upload
file_input = driver.find_element_by_id("uploadBtn")
file_input.send_keys("/absolute/path/to/file")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment