使用Selenium webdriverJs+;Javascript
我试图使用sendKeys('text');要使用以下代码将文本发送到标记内部的输入字段:使用Selenium webdriverJs+;Javascript,javascript,selenium,typescript,selenium-webdriver,automated-tests,Javascript,Selenium,Typescript,Selenium Webdriver,Automated Tests,我试图使用sendKeys('text');要使用以下代码将文本发送到标记内部的输入字段: this.driver.findElement(webdriver.By.css('table:last tr:last td:first input')).sendKeys('button'); this.driver.findElement(webdriver.By.css('table:last tr:last td:nth-of-type(1) input:nth-of-type(1)')).se
this.driver.findElement(webdriver.By.css('table:last tr:last td:first input')).sendKeys('button');
this.driver.findElement(webdriver.By.css('table:last tr:last td:nth-of-type(1) input:nth-of-type(1)')).sendKeys('button');
DOM如下所示:
运行代码时,会产生以下错误:
InvalidSelectorError: invalid selector: An invalid or illegal selector was specified
(Session info: chrome=60.0.3112.113)
我正在我的环境中运行“selenium webdriver”:“^3.5.0”
任何关于如何使用sendKeys(“”)的想法;要在输入字段中输入文本
更新截图:
由于您试图向输入字段发送值:
driver.findElement(webdriver.By.css('tr.ng-scope td input.ng-dirty')).sendKeys('someText');
请注意,此选择器基于我从所附的屏幕截图中看到的内容,如果此选项不起作用,则可能希望看到整个表的更大屏幕截图以进行调整。您所说的向表发送键是什么意思?此外,我在您共享的DOM中没有看到任何表。根据您共享的内容,我只能假设您希望实际将密钥发送到该标记内的输入字段。这是正确的吗?对不起,是的,请使用sendKeys到标记内的输入字段。请阅读原因。粘贴代码并正确格式化。你能在table标签周围给出html代码吗?你给出的屏幕截图只集中在td内的输入框上。我想在css定位器中使用tr的祖先使定位器更加严格和准确。您键入错误的伪元素,:last应该是:last child,:first应该是:first child尝试了上述操作,但没有成功,错误如下:NoSuchElementError:没有这样的元素:无法定位元素:{“方法”:“css选择器”,“选择器”:“tr.ng-scope td input.ng dirty”}(会话信息:chrome=60.0.3112.113)(驱动程序信息:chromedriver=2.32.498550(9DEC586C31BC53A9CE3C7226F0C1C5810906A),平台=Windows NT 10.0.15063 x86_64)