Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.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/3/xpath/2.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
Css 没有得到这样的元素异常_Css_Xpath - Fatal编程技术网

Css 没有得到这样的元素异常

Css 没有得到这样的元素异常,css,xpath,Css,Xpath,我得到错误,因为在执行某个测试应用程序的代码时找不到元素。我已经编写了使用css和xpath定位元素的代码,但仍然遇到同样的问题。有人能帮忙吗 代码: public static WebDriver driver; public static void setUp() { System.setProperty("webdriver.ie.driver", "Resources\\IEDriverServer.exe"); driver = new I

我得到错误,因为在执行某个测试应用程序的代码时找不到元素。我已经编写了使用css和xpath定位元素的代码,但仍然遇到同样的问题。有人能帮忙吗

代码:

public static WebDriver driver;

    public static void setUp() {

        System.setProperty("webdriver.ie.driver", "Resources\\IEDriverServer.exe"); 
        driver = new InternetExplorerDriver();

        //System.setProperty("webdriver.gecko.driver", "D:\\selenium\\geckodriver\\geckodriver.exe");   

        driver.get("http://demo.actitime.com/");
        driver.manage().window().maximize();

        driver.findElement(By.id("username")).sendKeys("user");

        driver.findElement(By.name("pwd")).sendKeys("user");

        driver.findElement(By.cssSelector("#loginButton > div")).click();

        //Wait<WebDriver> wait=new WebDriverWait(driver, 30);

        //wait.until(ExpectedConditions.presenceOfElementLocated(By.id("logoutLink")));

        //String parentWindow= driver.getWindowHandle();

        driver.findElement(By.cssSelector("div.popup_menu_icon.support_icon > div.popup_menu_arrow")).click();

//driver.findElement(By.xpath("id('topnav')/x:tbody/x:tr[1]/x:td[5]/x:table/x:tbody/x:tr/x:td[2]/x:div/x:table/x:tbody/x:tr[2]/x:td/x:div/x:div[2]/x:div/x:div[1]/x:div[2]")).click();


        driver.findElement(By.linkText("User Guide")).click();
    }

    public static void tearDown() {
        driver.quit();
    }

    public static void main(String[] args) {


        // TODO Auto-generated method stub

        setUp();

        tearDown();


    }

}

当您单击登录按钮时,浏览器需要几秒钟来发送请求并返回/呈现响应页面,但在代码中,您试图在单击登录按钮后立即单击帮助按钮帮助按钮尚未显示,在当前页面中找不到您要查找的元素,因为你还在登录页面上

因此,您需要等待登录后的页面呈现,然后您可以选择并单击您想要的任何内容

要等待元素可单击,请使用以下代码:

WebDriverWait wait = new WebDriverWait(driver, timeoutInSeconds);
wait.until(ExpectedConditions.elementToBeClickable(cssSelector("div.popup_menu_icon.support_icon > div.popup_menu_arrow"))); 
编辑:

似乎您使用了错误的css选择器。试试这个:

cssSelector("div.popup_menu_button.popup_menu_button_support")

请将错误消息添加到您的问题中好吗?thread main org.openqa.selenium.NoSuchElementException中的异常:无法使用css选择器==div.popup\u menu\u icon.support\u icon>div.popup\u menu\u箭头找到元素警告:服务器未提供任何stacktrace信息命令持续时间或超时:834毫秒用于文档关于这个错误,请访问:从dev.tools上的快速搜索显示此页面上没有弹出内容,既没有类也没有id,等等。登录到应用程序后,我试图单击右上角的帮助图标。我无法单击帮助图标,因为我遇到了错误嘿,我根据你的信息尝试了。。添加了外部等待命令。但我仍然得到错误的元素没有找到。下面是错误信息。嘿,我根据你的信息尝试了。。添加了外部等待命令。但我仍然得到错误的元素没有找到。下面是错误信息。线程主org.openqa.selenium.TimeoutException中的异常:预期条件失败:等待元素可单击:By.css选择器:div.popup_菜单图标。支持图标>div.popup_菜单箭头尝试了50秒,间隔500毫秒。问题得到修复,我可以选择用户指南。根据以下命令更改css选择器。字符串parentWindow=driver.getWindowHandle;wait.untelexpectedconditions.element tobeclickableby.cssSelectordiv.popup\u menu\u icon.support\u icon.click;伟大的如果答案对你有帮助,请不要忘记接受!当然非常感谢。