[英]To send threekeys using send_keys() in selenium python webdriver
[英]Removing square brackets when using send_keys in Python (Selenium)
當我使用用戶輸入 '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)
嘗試用這個替換第二行:
user_input_to_string = ''.join(x for x in user_input)
看起來您現在擁有的是將列表轉換為字符串。 這將將該列表的元素連接成一個字符串,這只是非常微妙的不同,可能是您所追求的。
將.strip("[]")
到user_input_to_string variable
的末尾:
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)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.