[英]WebElement Object.text returns a specific string that can't be stripped
I'm using selenium webdriver with Python3. 我在Python3中使用Selenium Webdriver。 I've extracted a webelement with the following command:
我使用以下命令提取了一个webelement:
ul = driver.find_element(By.CSS_SELECTOR, '.select2-selection__rendered')
this the HTML snipped I'm dealing with: 这是我正在处理的HTML片段:
<li class="select2-selection__choice" title="XX" data-select2-id="10"><span class="select2-selection__choice__remove" role="presentation">×</span>XX</li><li class="select2-selection__choice" title="admin" data-select2-id="11"><span class="select2-selection__choice__remove" role="presentation">×</span>admin</li><li class="select2-selection__choice" title="Test" data-select2-id="12"><span class="select2-selection__choice__remove" role="presentation">×</span>Test</li><li class="select2-search select2-search--inline"><input class="select2-search__field" type="search" tabindex="0" autocomplete="off" autocorrect="off" autocapitalize="none" spellcheck="false" role="textbox" aria-autocomplete="list" placeholder="" style="width: 0.75em;"></li>
now if I do ul.text
I get ×XX\\n×admin\\n×Test
and type(ul.text)
returns class str
Now, wish to get rid of the small "x" in the beginning, so I split and take the first substring which is xXX
and save it to variable first
. 现在,如果我执行
ul.text
我得到×XX\\n×admin\\n×Test
并且type(ul.text)
返回class str
现在,希望一开始就摆脱小写的“ x”,所以我拆分并取走第一个子字符串为xXX
,并将其first
保存到变量中。 I tried the following and it doesn't work: 我尝试了以下操作,但不起作用:
first.strip('x')
first.replace('x', ' ') or first.replace('x', '')
first.split('x')
temp = copy.copy(first)
temp.split('x')
temp.replace('x', ' ') or temp.replace('x', '')
temp.strip('x')
However, if I manually write 'xXX' and do any of the above it works. 但是,如果我手动编写“ xXX”并执行以上任何操作,则它可以工作。 Does anyone have an explanation and a solution for that?
有人对此有解释和解决方案吗?
used strip, replace, split and copy.copy 用过的剥离,替换,分割和复制
The "small x" in the beginning of "×XX\\n×admin\\n×Test" isn't an "x" it is a multiplication sign. “×XX \\ n×admin \\ n×Test”开头的“小x”不是“ x”,而是一个乘法符号。 (Alt + 0215 = ×).
(Alt + 0215 =×)。 You can copy and paste the multiplication sign from your string or use my code below.
您可以从字符串中复制并粘贴乘法符号,也可以使用下面的代码。
first.split('×') first.split('×')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.