简体   繁体   English

带有硒的 Powershell:错误:元素不可交互

[英]Powershell with Selenium: Error: element not interactable

I need to update a textarea with a value.我需要用一个值更新一个文本区域。 The code below throws an error "element not interactable".下面的代码抛出错误“元素不可交互”。 This is because the textarea has "display:none".这是因为 textarea 有“display:none”。 If I remove the word NONE manually and then run the script again, it works great and is able to set the value of the textarea.如果我手动删除单词 NONE 然后再次运行脚本,它会很好地工作并且能够设置 textarea 的值。

$browser = Start-SeChrome
$url = "https://www.freepik.com/profile/login"
$browser.Navigate().GoToURL($url)

$CaptchaResponse = "03AGdBq27yHAQ62QjKrtg"
ForEach ($TextArea_Element in (Find-SeElement -Driver $browser -TagName TextArea))
   {
   if ($TextArea_Element.GetAttribute('id') -eq "g-recaptcha-response") {$TextArea_Element.SendKeys($CaptchaResponse)}   
   Break
   }   

So the only option available is to use Javascript so that I can interact with the DOM directly ( https://fijiaaron.wordpress.com/2018/01/29/how-to-access-elements-when-you-get-elementnotinteractableexception/ ).所以唯一可用的选择是使用 Javascript 以便我可以直接与 DOM 交互( https://fijiaaron.wordpress.com/2018/01/29/how-to-access-elements-when-you-get-elementnotinteractableexception / )。 So I would have to do something like this:所以我必须做这样的事情:

$browser.executeScript("document.getElementById('g-recaptcha-response').value = $CaptchaResponse")
$browser.executeScript("___grecaptcha_cfg.clients[0].L.L.callback($CaptchaResponse)")

But now I get a different set of errors: javascript error: Invalid or unexpected token但现在我得到了一组不同的错误:javascript 错误:无效或意外的令牌

Try to edit your code as below to execute js with variable:尝试如下编辑您的代码以使用变量执行 js:

$browser.executeScript("document.getElementById('g-recaptcha-response').value = arguments[0];", $CaptchaResponse)

As same as first line, you should extract the variable and replace to arguments[0]与第一行一样,您应该提取变量并替换为 arguments[0]

$browser.executeScript("___grecaptcha_cfg.clients[0].L.L.callback('arguments[0]');", $CaptchaResponse)

You can execute JS like this, use arguments to pass your variables into JavaScript:您可以像这样执行 JS,使用arguments将您的变量传递给 JavaScript:

$new_style = "display: block; left: 20px;"
$browser.executeScript("arguments[0].style='arguments[1]';", $element, $new_style)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Selenium ElementNotInteractableError:元素不可交互 - Selenium ElementNotInteractableError: element not interactable 硒元素不可相互作用 - selenium element not interactable 文本框 selenium javascript 类型的输入元素的元素不可交互错误 - Element not interactable error for input element of type textbox selenium javascript 如何使用 Javascript 等到元素在 Selenium 中可交互 - How to wait until element is interactable in Selenium using Javascript selenium.common.exceptions.ElementNotInteractableException:消息:使用Selenium和Python插入值时元素不可交互 - selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable while inserting value using Selenium and Python 似乎无法绕过这个错误 - “元素不可交互” - Can't seem to be able to bypass this error - "element not interactable" 量角器:元素当前不可交互,并且可能无法操纵 - Protractor: Element is not currently interactable and may not be manipulated 如何单击与硒和python不可交互的下拉菜单,然后选择一个选项? - How to click not interactable dropdown with selenium and python and select one option? 元素显示在 chromedriver DOM 中,但 Protractor 显示失败:元素不可交互 - Element displays in chromedriver DOM, but Protractor says Failed: element not interactable 无效元素状态:元素当前不可交互且不可操作 - invalid element state: Element is not currently interactable and may not be manipulated
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM