简体   繁体   English

无法在Selenium中找到元素尝试过的xpath,name,id,css选择器

[英]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.

相关问题 无法使用类名称,xpath或CSS选择器定位元素 - Unable to locate element with class name, xpath or CSS selector 使用 Selenium 和 Java 时无法定位元素:{“method”:“xpath”,“selector”:“//li[@id=”tablist1-tab3“]”} 错误 - Unable to locate element: {“method”:“xpath”,“selector”:“//li[@id=”tablist1-tab3“]”} error using Selenium and Java 无法使用xpath,id,name或css选择器找到按钮或链接 - Unable to locate the button or link using either xpath, id, name or css selector 线程“ main”中的异常org.openqa.selenium.NoSuchElementException:无此类元素:无法找到元素:{“ method”:“ id”,“ selector”:“ name”} - Exception in thread “main” org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {“method”:“id”,“selector”:“name”} Selenium 无法通过 id/name 定位元素 - Selenium unable to locate element by id/name Selenium WebDriver:Java:NoSuchElementException:无法找到元素:{“ method”:“ xpath”,“ selector”:“ // div [@ id ='manage_area'] / ul / li / div [2]”} - Selenium WebDriver: Java: NoSuchElementException: Unable to locate element: {“method”:“xpath”,“selector”:“//div[@id='manage_area']/ul/li/div[2]”} 无法定位元素:{"method":"css selector","selector":"#id_gender1"} - Unable to locate element: {"method":"css selector","selector":"#id_gender1"} 如何在 selenium webdriver java 中使用 css 选择器定位元素? - How to locate element using css selector in selenium webdriver java? 无法使用id / name / xpath / CSSSelector定位元素 - Unable to locate the element using id/name/xpath/CSSSelector 无法在Selenium 3.0中定位元素 - Not able to locate element in selenium 3.0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM