Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change the text of a span that acts like a button

I am working on writing automation tests for a custom web application. I am running into a problem where I can't change the text of a span. I have tried using driver.execute_script but have had no luck. (It would really help if I knew javascript better) As far as I know you can't click a span and the list is populated as a list of . What is the best way to change this text?

enter image description here

like image 241
Curryjl Avatar asked Mar 04 '15 20:03

Curryjl


People also ask

How do I change text in span?

Use the textContent property to change the text of a span element, e.g. span. textContent = 'Replacement text' . The textContent property will set the text of the span to the provided string, replacing any of the existing content.

Can span be clickable?

If an object of this type is attached to the text of a TextView with a movement method of LinkMovementMethod, the affected spans of text can be selected. If selected and clicked, the onClick(View) method will be called.

How do you text the span of an element?

Use the textContent property to get the text of a span element, e.g. const text = span. textContent . The textContent property will return the text content of the span and its descendants.


1 Answers

You need to set the innerHTML using execute_script():

driver.execute_script('arguments[0].innerHTML = "New value";', element)

where element should point to your span element, could be:

element = driver.find_element_by_css_selector('div.file-wrapper span.k-dropdown span.k-input')
like image 124
alecxe Avatar answered Oct 20 '22 01:10

alecxe