0

I want to use Python to edit an element on a webpage. I've been trying to figure out how to use selenium to do that. Right now, this is what I have so far...

driver = webdriver.Chrome()
driver.get('https://www.website.com')
elem = driver.find_element_by_id('id')
print(elem)

Reading through the documentation (http://selenium-python.readthedocs.io/getting-started.html) I noticed they do the following

elem.send_keys("pycon")
elem.send_keys(Keys.RETURN)

But I'm a little confused...is that changing the id name? I want to change a different aspect of the element I find. If you could point me in the right direction, or help me print out something more useful than elem (typical output looks like this (session="8428be97c843ee6fecc9038bceccbc0e", element="0.0761228464802568-1")), I'd really appreciate it!

2
  • You probably should explain a little more what you are trying to accomplish. What do you mean by edit an element? Your code shows you grabbing an element and printing the element reference which is why you are getting that odd result printed. If you want to see the HTML of the element that you have found try, print (elem.get_attribute('outerHTML')) Commented Sep 2, 2016 at 2:56
  • Yes, you can change element attribute value id,name etc using execute_script() but these changes will be effect only that time of execution. This will not be effect as permanent solution..if you want to know how make these changes let us know..:) – Commented Sep 2, 2016 at 4:07

1 Answer 1

2

Selenium isn't a tool to edit elements on website. It used commonly to automate tests imitating user behavior on website.

Sign up to request clarification or add additional context in comments.

4 Comments

Hmmm ok! Is there something you know of that is better? I've briefly looked at requests and webbrowser but maybe I'll look more into those
What exactly do you want edit on webpage? It Has to be permanent change?
No it doesn't have to be permanent. I'm just trying to temporarily change the type of an element
You can change attributes of elements on webpage using JavaScript. So maybe selenium will be enough. Thanks to it you can execute scripts using execute_script method.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.