[英]Not able to locate element in Selenium tried xpath,name,id,css selector
I have tried using the name, id, xpath. 我尝试使用名称,ID,xpath。 However I get the same error in Eclipse that it is not able to locate the element.
但是我在Eclipse中遇到了同样的错误,即它无法找到该元素。
WebDriver driver=new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("https://accenturenordicspov.service-now.com/navpage.do");
driver.findElement(By.xpath("/html/body/form/table/tbody/tr[3]/td[2]/input")).sendKeys("John");
driver.findElement(By.xpath("/html/body/form/table/tbody/tr[4]/td[2]/input[1]")).sendKeys("A***");
driver.findElement(By.id("/html/body/form/table/tbody/tr[7]/td[2]/button")).click();
According to the link you've given, the form is in an iframe
. 根据您提供的链接,该表单位于
iframe
。 Hence, you need to switch to the frame and then fill the form. 因此,您需要切换到框架,然后填写表格。 You should try this:
您应该尝试这样:
driver.switch_to.frame("gsft_main")
driver.findElement(By.xpath("//input[@id='user_name']").sendKeys("John");
driver.findElement(By.xpath("//input[@id='user_password']").sendKeys("A***");
driver.findElement(By.xpath("//button[@id='sysverb_login']").click();
May be in different frame. 可能在不同的框架中。 Kindly check for the frame or iframe tag is parent of the box you are going to interact.
请检查frame或iframe标签是否是要交互的框的父级。 If yeas then You have to switch to that frame then only You can interact.
如果是,那么您必须切换到该框架,那么只有您可以进行交互。
It first needs to move to that frame and then input the elements. 它首先需要移动到该框架,然后输入元素。 Above code will work if just put this piece of code before inputting the elements:
如果仅在输入元素之前放置以下代码,则上述代码将起作用:
String x="gsft_main";
driver.switchTo().frame(x);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.