【发布时间】:2020-01-08 11:33:14
【问题描述】:
我正在努力从文本框中获取文本,将其转换为整数,乘以 1.2,然后将其重新插入文本框。
我最初收到一条错误消息,说我无法将其转换为整数(即使字符串刚刚说“2000”),所以我尝试将其转换为浮点数并将 then 转换为整数,但是现在我收到“ValueError:无法将字符串转换为浮点数”。
有什么想法吗?我将附上文本框的 HTML 和我的 python。
HTML:
<input id="radius" ng-model="geoCtrl.lineRadius"
type="text" placeholder="Desired radius from each point of the list"
maxlength="100" name="targeting[geolocation][radius]"
ng-class="{'val-ignore': geoCtrl.options !== 'geo'}"
class="col-lg-12 attr-input ng-pristine ng-valid">
Python:
#code to find radius, multiply it by 1.2, then enter new radius into textbox
browser.find_element_by_id('radius')
first_radius_20percent = browser.find_element_by_id('radius')
current_radius = float(first_radius_20percent.get_attribute('value'))
current_radius = int(first_radius_20percent.get_attribute('value'))
new_radius = int(current_radius*1.2)
first_radius_20percent.clear()
first_radius_20percent.send_keys(new_radius)
【问题讨论】:
-
first_radius_20percent.get_attribute('value')返回什么?'2000'还是只在网站上看到? -
@Guy 它返回 u'2000' 编辑:实际上当我打印
first_radius_20percent.get_attribute('value')它只打印 '2000'
标签: python selenium selenium-webdriver integer selenium-chromedriver