Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/307.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
Java NoSuchElementException | Flipkart/Paytm |登录/注册_Java_Selenium_Selenium Webdriver - Fatal编程技术网

Java NoSuchElementException | Flipkart/Paytm |登录/注册

Java NoSuchElementException | Flipkart/Paytm |登录/注册,java,selenium,selenium-webdriver,Java,Selenium,Selenium Webdriver,我只是写了一个脚本来点击Flipkart/Paytm上的登录/注册链接,但每次运行脚本时,我都没有得到这样的元素例外 请看一下剧本,帮我做同样的事情 公务舱试驾{ WebDriver driver = null; @Before public void setUp() throws Exception { String basePath = System.getProperty("user.dir"); //System.out.println(basePath); S

我只是写了一个脚本来点击Flipkart/Paytm上的登录/注册链接,但每次运行脚本时,我都没有得到这样的元素例外

请看一下剧本,帮我做同样的事情

公务舱试驾{

WebDriver driver = null;

@Before
public void setUp() throws Exception {
    String basePath = System.getProperty("user.dir");
    //System.out.println(basePath);
    String finalPath = basePath + "\\IEDriver\\IEDriverServer.exe";
    //System.out.println(finalPath);

    System.setProperty("webdriver.ie.driver", finalPath);
    driver = new InternetExplorerDriver();
    driver.get("http://flipkart.com");
}

@After
public void tearDown() throws Exception {
    driver.close();
}

@Test
public void test() throws InterruptedException {
    driver.manage().window().maximize();
    driver.manage().timeouts().pageLoadTimeout(10, TimeUnit.SECONDS);
    System.out.println("a");
    //Thread.sleep(5000);
    driver.findElement(By.xpath("//*[@id='container']/div/div/header/div[2]/div/div[1]/ul/li[7]/a")).click();
    //driver.findElement(By.partialLinkText("Log in")).click();
    System.out.println("hie");
}

}

在使用链接文本时,您需要非常具体地说明大小写。我可以看到链接文本是带有大写字母I的“登录”

使用以下命令:

driver.findElement(By.partialLinkText("Log In")).click();

我可以在所有浏览器上使用。

在Python中,我可以在Flipkart网站上成功地做到这一点:

login\u link=驱动程序。通过链接文本(“登录”)查找元素
登录链接。单击()

另一种解决方案:

如果您没有测试登录按钮本身,您也可以在Flipkart(未验证PayTM)的情况下直接导航到
/account/login
页面。路径的名字看起来是静态的,你不必担心在主页上找到登录按钮的确切位置


例如:
driver.gethttps://www.flipkart.com/account/login“)

我发现您正在使用IE执行测试,而IE浏览器的xpath往往会中断,我想知道是否相同的代码在Firefox和/或Chrome上工作?是的,相同的代码在Firefox中工作…我甚至尝试在IE中使用Id或链接文本,但不起作用..然后你可以尝试为IE或所有其他浏览器使用CSS选择器。