Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/378.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/Selenium/html中的排序_Java_Selenium_Xpath_Wait - Fatal编程技术网

Java/Selenium/html中的排序

Java/Selenium/html中的排序,java,selenium,xpath,wait,Java,Selenium,Xpath,Wait,这是Java、Selenium和Chrome,尽管它也必须适用于IE和Firefox 我正在编写一个自动化脚本来验证网页。页面的一部分是一个包含以下列的表 " Name[ud] Dept[ud] Date[ud] Status[ud] ..." 有数千行数据 [ud]实际上是上下箭头,当您将鼠标悬停在列上时会出现,因此,如果单击其中一个箭头,它会对该列进行升序或降序排序。单击后,我将值列放入一个列表,制作列表的排序副本并进行比较。这有时有效。对数据进行排序需要一些时间。以下是三种情

这是Java、Selenium和Chrome,尽管它也必须适用于IE和Firefox

我正在编写一个自动化脚本来验证网页。页面的一部分是一个包含以下列的表

" Name[ud]   Dept[ud]   Date[ud]   Status[ud] ..."
有数千行数据

[ud]实际上是上下箭头,当您将鼠标悬停在列上时会出现,因此,如果单击其中一个箭头,它会对该列进行升序或降序排序。单击后,我将值列放入一个列表,制作列表的排序副本并进行比较。这有时有效。对数据进行排序需要一些时间。以下是三种情况

1) 排序的速度足够快,因此当我得到值时,它们已经被排序,并且测试工作正常

2) 排序需要一段时间,所以当我得到值时,它们仍然是预排序的值,在这种情况下,测试无效

3) 当我得到最终导致过时元素的值时,排序部分完成


这里的管理层不赞成使用线程。睡眠(毫秒),我不确定什么时候才是好时机。我找不到任何可以等待的xpath,因为路径在排序之前和之后。我正在寻找一种等待排序完成的方法。任何建议。有什么建议吗?我唯一能注意到的是,排序过程中光标会旋转。是否可以告诉Selenium等待光标停止旋转?

请参阅Selenium的WebDriver中的隐式和显式等待。你需要一个明确的等待

基本上,您可以等到表示表的WebElement可供浏览器使用

链接:

您可以使用Thread.sleep(10000);在这里它将等待10秒。
或者可以添加隐式等待

是。您可以等待旋转光标首先出现(
,以防它需要时间出现),然后等待它消失。这两个目的都可以使用。请使用以下代码

1-单击后,使用以下代码等待微调器出现:

try
{
    // Waits for 10 seconds so that the cursor appears
    WebDriverWait wait = new WebDriverWait(driver, 10);

    // Wait until the cursor is located on the page
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//xpath of the cursor")));
    System.out.println("Waiting ends ... Cursor Appeared in the page.");
}
catch (Throwable e){
    System.err.println("Error came while waiting for Cursor to Appear : " +e.getMessage());
}
try
{
    // Waits for 30 seconds so that the cursor disappear
    WebDriverWait wait = new WebDriverWait(driver, 30);

    // Wait until the cursor disappears from the page
    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//xpath of the cursor")));
    System.out.println("Waiting ends ... Cursor disappeared from the page.");
}
catch (Throwable e){
    System.err.println("Error came while waiting for Cursor to Disappear : " +e.getMessage());
}
2-使用以下代码等待微调器消失:

try
{
    // Waits for 10 seconds so that the cursor appears
    WebDriverWait wait = new WebDriverWait(driver, 10);

    // Wait until the cursor is located on the page
    wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//xpath of the cursor")));
    System.out.println("Waiting ends ... Cursor Appeared in the page.");
}
catch (Throwable e){
    System.err.println("Error came while waiting for Cursor to Appear : " +e.getMessage());
}
try
{
    // Waits for 30 seconds so that the cursor disappear
    WebDriverWait wait = new WebDriverWait(driver, 30);

    // Wait until the cursor disappears from the page
    wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//xpath of the cursor")));
    System.out.println("Waiting ends ... Cursor disappeared from the page.");
}
catch (Throwable e){
    System.err.println("Error came while waiting for Cursor to Disappear : " +e.getMessage());
}

您可以使用Selenium Webdriver中提供的隐式等待或流畅等待。

OP说管理层对Thread.sleep()皱眉头,隐式等待没有帮助,因为如果排序操作花费的时间超过指定的隐式等待时间,Webdriver可能会抛出异常(或返回null)。您可以在隐式等待中指定任意时间量。您还可以添加条件以等待任何特定的元素出现或可见是的,您可以设置任何时间量,但是OP如何知道要等待多少时间而不会效率低下?另外,等待元素出现/可见/可点击是显式的等待,而不是隐式的。或者您可以等待ajax请求完成增益,这是显式的等待,而不是隐式的。