Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过send_keys()发送的字符序列与通过Python和Selenium显示的默认文本连接在一起_Python_Python 3.x_Selenium_Selenium Webdriver_Webdriver - Fatal编程技术网

通过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