Следуя советам комментариев Salaman A , я нашел, как Google делает это сейчас с Analytics: https://developers.google.com/analytics/devguides/collection/gajs/asyncTracking
И вот более общая версия того же кода:
(function() {
var s = document.createElement('script'); // Create a script element
s.type = "text/javascript"; // optional in html5
s.async = true; // asynchronous? true/false
s.src = "//example.com/your_script.js";
var fs = document.getElementsByTagName('script')[0]; // Get the first script
fs.parentNode.insertBefore(s, fs);
})();
В соответствии с 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_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