通过send_keys()发送的字符序列与通过Python和Selenium显示的默认文本连接在一起
我有以下领域:通过send_keys()发送的字符序列与通过Python和Selenium显示的默认文本连接在一起,python,python-3.x,selenium,selenium-webdriver,webdriver,Python,Python 3.x,Selenium,Selenium Webdriver,Webdriver,我有以下领域: <input name="accountId" required="" type="text" id="accountId" class="active form-control" value="90646301"> 当我的测试运行时,它在“帐户”字段中输入90646301123455。换句话说,它连接值和我的字符串 我如何才能只输入我传递的字符串?根据您共享的HTML,您需要诱导WebDriverWait以使元素可单击,并且您可以使用以下解决方案: myInput
<input name="accountId" required="" type="text" id="accountId" class="active form-control" value="90646301">
当我的测试运行时,它在“帐户”字段中输入90646301123455
。换句话说,它连接值和我的字符串
我如何才能只输入我传递的字符串?根据您共享的HTML,您需要诱导WebDriverWait以使元素可单击,并且您可以使用以下解决方案:
myInput = WebDriverWait(self.driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.active.form-control#accountId")))
# or
myInput = WebDriverWait(self.driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//input[@class='active form-control' and @id='accountId']")))
myInput.click()
myInput.clear()
myInput.send_keys('12345')
或者,您也可以使用execute\u script()
方法,如下所示:
myInput = WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.active.form-control#accountId")))
driver.execute_script("arguments[0].removeAttribute('value')", myInput);
driver.execute_script("arguments[0].setAttribute('value','123455')", myInput);
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC