I got attribute from Selenium Element and it contains empty char or spaces:
When I double click the result :
What I tried so far :
string.replace(" ","") #didnt work
So I came with this resolution (I know its bad ):
edit1 = ticketID[:1]
ticketF = ticketID.replace(edit1,"")
edit2 = ticketF[:1]
ticketE = ticketF.replace(edit2,"")
edit3 = ticketE[:1]
ticketD = ticketE.replace(edit3,"")
What Im looking for is what is those blanks ? tabs ? new lines ? how to make it better ?
ticketID.replace("\n","")
ticketID.replace(" ","")
ticketID.strip()
CodePudding user response:
Those are basically whitespaces, Please use .strip()
for any trailing spaces.
In Python, the stripping methods are capable of removing leading and trailing spaces and specific characters. The leading and trailing spaces include blanks
, tabs
(\t)
, carriage returns (\r, \n)
, and the other lesser-known whitespace characters.
If you have ele
as an web element.
You can use .text
to get the text and then on top of that use .strip()
Probably in your code :
ticketID.text.strip()
CodePudding user response:
They look like lines and not spaces to me.
string.replace("\n","")