Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/459.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
通过javascript使用Selenium选择td单元时出现的问题_Javascript_Selenium_Xpath - Fatal编程技术网

通过javascript使用Selenium选择td单元时出现的问题

通过javascript使用Selenium选择td单元时出现的问题,javascript,selenium,xpath,Javascript,Selenium,Xpath,这是HTML,我需要选择文本字段,它被选中输入id=登录名=j_用户名。。。。。。 这是我现在的JS文件 var webdriver = require ('selenium-webdriver'), By = webdriver.By, until = webdriver.until; var driver = new webdriver.Builder().forBrowser('chrome').build(); driver.get('https://student.tuke.sk/

这是HTML,我需要选择文本字段,它被选中输入id=登录名=j_用户名。。。。。。 这是我现在的JS文件

var webdriver = require ('selenium-webdriver'),
By = webdriver.By,
until = webdriver.until;

var driver = new webdriver.Builder().forBrowser('chrome').build();

driver.get('https://student.tuke.sk/student/home.mais;jsessionid=18C8A365CEB230018870BF5F6884F3F9');
driver.findElement(By.xpath('//*[@id="login"]/input')).click();
driver.sleep(1500);
driver.findElement(By.xpath('/body/table/tbody/tr/td/div/div/form/div/table/tbody/tr/td/input[@id="login"]'))
.sendKeys('rk096jv');

我只是不能正确地选择它,它总是告诉我NoTouchElementError无法找到元素。有没有办法选择该字段并在其中写入我的凭据?谢谢你

没有完整的HTML,很难说你的定位器为什么不工作。我的猜测是,在定位器中的DOM的15个级别的某个地方是一个问题。这就是为什么应该避免使用那么深的定位器。我会做一些更简单的事情,比如这个CSS选择器

#loginForm #login

确保添加了适当的等待,以等待可见,而不是睡眠。

在运行页面的脚本截图之前,确保HTML存在。请阅读原因。粘贴代码并正确格式化。您需要使用等待并使用名称查找它。Selenium处理这个问题。我看到你设置到,但你曾经使用过它。你为什么不用它?