我目前很难将值插入到框架内的字段中,我尝试过删除类名中的空格,但没有成功
class="ng-原始ng-有效ng-范围ng-空输入-sm表单-控制nc-原始ng-有效-必需ng-触摸"
<textarea ng-if="$ctrl.fieldType.isTextarea($ctrl.field.fieldType, $ctrl.field.isHtmlFormatted)" ng-model="$ctrl.field.value" ng-change="$ctrl.onChange()" ng-required="$ctrl.field.isRequired" ng-class="{
'input-sm': true,
'form-control': true,
'nc-pristine': $ctrl.getPristine(),
'nc-not-pristine': $ctrl.getNotPristine()
}" class="ng-pristine ng-valid ng-scope ng-empty input-sm form-control nc-pristine ng-valid-required ng-touched"></textarea>
我尝试过Chrome开发者工具,它适用于这个javascript代码
Chrome控制台开发器Javascript
document.getElementsByClassName('ng-pristine ng-valid ng-scope ng-empty input-sm form-control nc-pristine ng-valid-required ng-touched')[0].value='Hello World';
在Selenium中,我尝试了以下两种方法,但均无效:
使用Javascript
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("document.getElementsByClassName('ng-pristine ng-valid ng-scope ng-empty input-sm form-control nc-pristine ng-valid-required ng-touched')[0].value='Hello World';");
错误消息:
System.InvalidOperationException occurred
HResult=0x80131509
Message=unknown error: Cannot set property 'value' of undefined
(Session info: chrome=62.0.3202.94)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.15063 x86_64)
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScriptCommand(String script, String commandName, Object[] args)
at OpenQA.Selenium.Remote.RemoteWebDriver.ExecuteScript(String script, Object[] args)
at ConsoleApp5.Program.Main(String[] args)
使用cssSelector,删除类名中的间距并将其替换为点
driver.FindElement(By.CssSelector("ng-pristine.ng-valid.ng-scope.ng-empty.input-sm.form-control.nc-pristine.ng-valid-required.ng-touched")).SendKeys("Hello World");
错误消息
OpenQA.Selenium.NoSuchElementException occurred
HResult=0x80131500
Message=no such element: Unable to locate element: {"method":"css selector","selector":"ng-pristine.ng-valid.ng-scope.ng-empty.input-sm.form-control.nc-pristine.ng-valid-required.ng-touched"}
(Session info: chrome=62.0.3202.94)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.15063 x86_64)
Source=WebDriver
StackTrace:
at OpenQA.Selenium.Remote.RemoteWebDriver.UnpackAndThrowOnError(Response errorResponse)
at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(String mechanism, String value)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElementByCssSelector(String cssSelector)
at OpenQA.Selenium.By.<>c__DisplayClass23_0.<CssSelector>b__0(ISearchContext context)
at OpenQA.Selenium.By.FindElement(ISearchContext context)
at OpenQA.Selenium.Remote.RemoteWebDriver.FindElement(By by)
请尝试以下代码块:
IJavaScriptExecutor js = (IJavaScriptExecutor)driver;
js.ExecuteScript("document.getElementsByClassName('ng-pristine ng-valid ng-scope ng-empty input-sm form-control nc-pristine ng-valid-required ng-touched')[0].click()");
js.ExecuteScript("document.getElementsByClassName('ng-pristine ng-valid ng-scope ng-empty input-sm form-control nc-pristine ng-valid-required ng-touched')[0].value='Hello World'");
下面是更多HTML代码
<div class="row ng-scope" ng-repeat="field in $ctrl.getFields() as fields" ng-if="$index % 2 == 0">
<!-- ngRepeat: i in [$index, $index + 1] --><!-- ngIf: fields[i] --><nc-form-group-template ng-repeat="i in [$index, $index + 1]" ng-if="fields[i]" section-id="a1gg0000002ARlMAAW" guid="a1gg0000002ARlMAAW338C1B4330ED4993A7B3178099C70517" field="fields[i]" context-id="a38g0000001juVQAAY" ,="" enable-field-access="$ctrl.enableFieldAccess" class="ng-scope ng-isolate-scope">
<div class="form-group col-xs-6">
<nc-field-label-template section-id="a1gg0000002ARlMAAW" field="$ctrl.field" inline-help-text="" label="Other Loan Purpose" is-required="$ctrl.field.isRequired" enable-field-access="$ctrl.enableFieldAccess" class="ng-isolate-scope">
<div class="row content-label">
<div class="col-xs-12">
<span ng-show="$ctrl.inlineHelpText" popover="popover" data-toggle="popover" data-content="" class="fa fa-info-circle slds-show--inline ng-hide" data-original-title="" title="">
</span>
<label ng-bind="$ctrl.label" class="form-control-static input-sm slds-show--inline ng-binding" ng-class="{'is-required': $ctrl.isRequired, 'pull-left': $ctrl.enableFieldAccess}">Other Loan Purpose</label>
<span class="slds-p-left--medium">
<!-- ngIf: !$ctrl.field.isVisible && $ctrl.enableFieldAccess -->
<span class="slds-assistive-text">This field will be hidden from the user.</span>
</span>
<!-- ngIf: $ctrl.enableFieldAccess -->
</div>
</div>
</nc-field-label-template>
<!-- ngIf: !$ctrl.isReadOnly() --><nc-editable-field-template ng-if="!$ctrl.isReadOnly()" section-id="a1gg0000002ARlMAAW" guid="a1gg0000002ARlMAAW338C1B4330ED4993A7B3178099C70517" field="$ctrl.field" context-id="a38g0000001juVQAAY" class="ng-scope ng-isolate-scope">
<div class="row">
<div class="col-xs-12 content-body">
<nc-editable-field section-id="a1gg0000002ARlMAAW" guid="a1gg0000002ARlMAAW338C1B4330ED4993A7B3178099C70517" field="$ctrl.field" context-id="a38g0000001juVQAAY" class="ng-isolate-scope">
<!-- ngIf: $ctrl.fieldType.isTextarea($ctrl.field.fieldType, $ctrl.field.isHtmlFormatted) --><textarea ng-if="$ctrl.fieldType.isTextarea($ctrl.field.fieldType, $ctrl.field.isHtmlFormatted)" ng-model="$ctrl.field.value" ng-change="$ctrl.onChange()" ng-required="$ctrl.field.isRequired" ng-class="{
'input-sm': true,
'form-control': true,
'nc-pristine': $ctrl.getPristine(),
'nc-not-pristine': $ctrl.getNotPristine()
}" class="ng-pristine ng-valid ng-scope ng-empty input-sm form-control nc-pristine ng-valid-required ng-touched"></textarea><!-- end ngIf: $ctrl.fieldType.isTextarea($ctrl.field.fieldType, $ctrl.field.isHtmlFormatted) -->
如果提供了html,请尝试以下操作:
driver.findElement(By.cssSelector("div > div > nc-editable-field > textarea"));
另外,您声明元素在Frame中,您确定您正确切换到该框架吗?
问题内容: 我有下面的代码,单击一个元素以弹出一个屏幕并在其中复制文本 但是,当我尝试单击该弹出窗口中的按钮时, 它产生一条错误消息: 这是我要单击的HTML 。该按钮。 我应该怎么写才能单击关闭按钮? 问题答案: Leon的评论提出了正确的信息,即不再支持复合类名称。相反,您可以尝试使用CSS选择器。在您的情况下,以下代码行应帮助您获取所需的元素: 它在class属性中找到具有所有三个类(act
我有下面的代码,点击一个元素弹出一个屏幕并复制其中的文本 我应该如何编写以便单击关闭按钮?
问题内容: 我有下面的代码,单击一个元素以弹出一个屏幕并在其中复制文本 但是,当我尝试单击该弹出窗口中的按钮时, 它产生一条错误消息: 这是我要单击的HTML 。该按钮。 我应该怎么写才能单击关闭按钮? 问题答案: Leon的评论提出了正确的信息,即不再支持复合类名称。相反,您可以尝试使用CSS选择器。就您而言,以下代码行应帮助您获取所需的元素: 它在class属性中找到具有所有三个类(actio
尝试创建自动订阅新闻的脚本,但是遇到了一个问题,< code>selenium找不到电子邮件输入和提交按钮。每次获取< code > selenium . common . exceptions . nosuchelementexception:
我试图获取具有特定类名的所有元素: 然而我得到的错误是: 我知道类名中不允许有空格,但是我该怎么办呢? 谢啦
我有一个表,列:,,。我试图实现简单的插入功能,但当我提交表单时,我无法将NULL值插入“name”列、table“database_name”中。dbo。用户的;列不允许空值。插入失败。 我正在学习这个教程。 地点主人 请帮忙,提前谢谢!