Python 当使用Selenium选择时,按钮将丢失操作

Python 当使用Selenium选择时,按钮将丢失操作,python,selenium,selenium-webdriver,Python,Selenium,Selenium Webdriver,我正在尝试使用Python自动化Selenium的登录流。当我手动执行流程时,一切都按预期进行。我可以使用webdriver加载网页,但一旦我选择了用户名字段,在尝试提交时,我会在浏览器控制台中看到以下错误: ERROR TypeError: Cannot read property 'action' of null 我尝试通过Selenium导航到该页面,然后手动填写用户名,它将成功提交。但是,如果脚本导航到页面,然后选择目标字段,则在提交字段时会发生错误,即使在脚本等待时手动填充并提交字段

我正在尝试使用Python自动化Selenium的登录流。当我手动执行流程时,一切都按预期进行。我可以使用webdriver加载网页,但一旦我选择了用户名字段,在尝试提交时,我会在浏览器控制台中看到以下错误:

ERROR TypeError: Cannot read property 'action' of null
我尝试通过Selenium导航到该页面,然后手动填写用户名,它将成功提交。但是,如果脚本导航到页面,然后选择目标字段,则在提交字段时会发生错误,即使在脚本等待时手动填充并提交字段也是如此。我知道该字段被成功地定位,因为send_keys调用正确地填充了它。通过Selenium选择页面上的任何元素都会导致相同的问题。这似乎只影响触发页面更新而不路由的控件;链接到其他页面的按钮仍按预期运行

我的代码在此阶段非常基本,大致如下所示:

chrome_options = Options()
driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)

driver.get("https://www.targetwebsite.com")

# Executing this line, or anything using a locator, seems to cause the issue
element = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, "usernameTextBox")))

element.send_keys("username")
element.send_keys(Keys.ENTER)
script = "arguments[0].value=" + username         #if element is input type
script = "arguments[0].innerText=" + username     #if element is button
driver.execute_script(script,element)
我要针对的输入字段:

<input _ngcontent-c7 appformatter class="text_box input_box ng-pristine ng-invalid remote-accessable focusable ng-touched" id="usernameTextBox" type="text" aria-label="username">

我试着换掉Chromedriver,改用Geckodriver和Firefox,但也有同样的问题。
你知道这是什么原因吗?在使用Selenium之前,我从未见过类似的情况。

尝试使用JavaScript与元素进行交互,看看是否得到相同的行为。这样做:

chrome_options = Options()
driver = webdriver.Chrome(executable_path=chrome_driver_path, options=chrome_options)

driver.get("https://www.targetwebsite.com")

# Executing this line, or anything using a locator, seems to cause the issue
element = WebDriverWait(driver, 30).until(EC.presence_of_element_located((By.ID, "usernameTextBox")))

element.send_keys("username")
element.send_keys(Keys.ENTER)
script = "arguments[0].value=" + username         #if element is input type
script = "arguments[0].innerText=" + username     #if element is button
driver.execute_script(script,element)

对于Enter键,请检查是否可以通过单击按钮来执行此操作。否则,请使用与selenium相同的方法。

是否加载页面。我试图手动导航的网址,我得到的网站无法达到错误,你可以请提供html代码。在我看来,它没有识别用户名文本box@Sonali这不是真正的网站,我使用了一个地方持有人的隐私原因,因为这是一个商业项目。当手动导航到时,实际页面将成功加载并运行。我将编辑帖子以添加HTML代码段。@Sonali定位器不是问题所在,因为当我向元素发送键时,它们会正确填充。我尝试使用javascript执行器,但也遇到了同样的问题。简单地选择控件,即使不向其发送键,也会破坏提交。