当我使用用户输入'111‘运行这段代码时,它会在web元素中键入[111]。
如何删除方括号,使其只键入111?
看起来非常简单,但到处都找不到解决方案。
campaign_text_field = browser.find_element(By.XPATH, "//input[@placeholder='Search']")
user_input_to_string = str(user_input)
campaign_text_field.send_keys(user_input_to_string)发布于 2020-01-11 02:52:25
尝试用下面的代码替换第二行:
user_input_to_string = ''.join(x for x in user_input)看起来您现在拥有的是将列表转换为字符串。这将把该列表的元素连接成一个字符串,这只是非常微妙的不同,这可能就是您想要的。
发布于 2020-01-11 03:07:36
在user_input_to_string variable末尾添加了.strip("[]"):
campaign_text_field = browser.find_element(By.XPATH, "//input[@placeholder='Search']")
user_input_to_string = str(user_input).strip("[]")
campaign_text_field.send_keys(user_input_to_string)https://stackoverflow.com/questions/59687162
复制相似问题