Не навигация по pagination3 и исключение устаревших элементов - PullRequest
0 голосов
/ 07 ноября 2019

Мне нужно перемещаться по страницам и проверять службы на каждой странице вниз или вверх, но при навигации по странице 3 сообщение об ошибке отображается как исключение устаревшего элемента.

Я пытался использовать этот код, но он не работает нормально,кто-то, пожалуйста, помогите мне в этом.

public class TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer {
    public static void TC_2377154_12236() {
        try {
            Assert.done("Start -> TC_2377154_12236");

            //BaseSetUp.openBrowser();
            WebDriver driver = FrameworkDriver.driver;
            driver.get("https://webtech.humana.com/nes/servicesview.aspx"); 
            Assert.assertTrue(driver.findElement(By.xpath("//input[@id='tbLBVServerName']")).isDisplayed(), "LBV Server name is displayed");
            driver.findElement(By.xpath("//input[@id='tbLBVServerName']")).sendKeys("SRS");

            Assert.assertTrue(driver.findElement(By.xpath("//input[@id='btnFilter']")).isDisplayed(),"Filter button is displayed");
            driver.findElement(By.xpath("//input[@id='btnFilter']")).click();

            Assert.assertTrue(driver.findElement(By.xpath("//table[@id='dgServices']")).isDisplayed(),"Services name table is Displayed");
            WebDriverWait wait = new WebDriverWait(driver, 20);
            wait.until( ExpectedConditions.presenceOfElementLocated(
                                          By.xpath("//a[@style='color:Black;']")));

            List<WebElement> pagination = driver.findElements(By.xpath("//a[@style='color:Black;']"));
            int s = pagination.size()/2;
            System.out.println(s +"Pagination list");
            for(int i=0;i<=s;i++){
                List<WebElement> ls = driver
                        .findElements(By
                                .xpath("//font[@color='red']"));
                System.out.println(ls.size()+"list of Down services size");
                if (ls.size() > 1)
                        Assert.fail("All service states are expected Up and Running but there are "+(ls.size()+" servers are down")); 
                else if (ls.size() == 0)
                    Assert.fail("****Some technical issue or No Server is up or running****");
                else if (ls.size() == 1)
                    Assert.pass("~~All Servers are Up and running~~");

                    Thread.sleep(5000);

                //  ls.get(i).click();
                 // Thread.sleep(5000);
                 System.out.println( pagination.get(i)); 
                 //driver.findElement(By.xpath("//a[@style='color:Black;']")).click();
                 pagination.get(i).click();

           Thread.sleep(5000);
        }

        Assert.done("End -> TC_2377154_12236");

        }  catch (Exception e) {

            Assert.error(e, "Error -> TC_2377154_12236");
        }
    }
}

Я ожидал вывода, так как он должен нажимать на каждую страницу, но с ошибкой ниже

TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : PASS - Filter button is displayed
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : PASS - Services name table is Displayed
7Pagination list
5list of Down services size
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : FAIL - All service states are expected Up and Running but there are 5 servers are down
[[ChromeDriver: chrome on XP (4f932cb86e8057b5ecda92c582500243)] -> xpath: //a[@style='color:Black;']]
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : FAIL - Error -> TC_2377154_12236.  Error:stale element reference: element is not attached to the page document
  (Session info: chrome=77.0.3865.90)
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'WKR90LDWJ0', ip: '10.94.27.177', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_192'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.37.544315 (730aa6a5fdba15..., userDataDir: C:\Users\VAM1449\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 77.0.3865.90, webStorageEnabled: true}
Session ID: 4f932cb86e8057b5ecda92c582500243 Stack Trace: [Ljava.lang.StackTraceElement;@18d3f76
FAIL Error:stale element reference: element is not attached to the page document
  (Session info: chrome=77.0.3865.90)
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'WKR90LDWJ0', ip: '10.94.27.177', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_192'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.37.544315 (730aa6a5fdba15..., userDataDir: C:\Users\VAM1449\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 77.0.3865.90, webStorageEnabled: true}
Session ID: 4f932cb86e8057b5ecda92c582500243 Stack Trace: 
org.openqa.selenium.StaleElementReferenceException: stale element reference: element is not attached to the page document
  (Session info: chrome=77.0.3865.90)
  (Driver info: chromedriver=2.37.544315 (730aa6a5fdba159ac9f4c1e8cbc59bf1b5ce12b7),platform=Windows NT 10.0.16299 x86_64) (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 0 milliseconds
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/stale_element_reference.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'
System info: host: 'WKR90LDWJ0', ip: '10.94.27.177', os.name: 'Windows 10', os.arch: 'x86', os.version: '10.0', java.version: '1.8.0_192'
Driver info: org.openqa.selenium.chrome.ChromeDriver
Capabilities {acceptInsecureCerts: false, acceptSslCerts: false, applicationCacheEnabled: false, browserConnectionEnabled: false, browserName: chrome, chrome: {chromedriverVersion: 2.37.544315 (730aa6a5fdba15..., userDataDir: C:\Users\VAM1449\AppData\Lo...}, cssSelectorsEnabled: true, databaseEnabled: false, handlesAlerts: true, hasTouchScreen: false, javascriptEnabled: true, locationContextEnabled: true, mobileEmulationEnabled: false, nativeEvents: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, rotatable: false, setWindowRect: true, takesHeapSnapshot: true, takesScreenshot: true, unexpectedAlertBehaviour: , unhandledPromptBehavior: , version: 77.0.3865.90, webStorageEnabled: true}
Session ID: 4f932cb86e8057b5ecda92c582500243
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:214)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:166)
    at org.openqa.selenium.remote.http.JsonHttpResponseCodec.reconstructValue(JsonHttpResponseCodec.java:40)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:80)
    at org.openqa.selenium.remote.http.AbstractHttpResponseCodec.decode(AbstractHttpResponseCodec.java:44)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:83)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:552)
    at org.openqa.selenium.remote.RemoteWebElement.execute(RemoteWebElement.java:285)
    at org.openqa.selenium.remote.RemoteWebElement.click(RemoteWebElement.java:84)
    at com.humana.hss.scripts.TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer.TC_2377154_12236(TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer.java:54)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.dell.acoe.framework.run.ExecutionThread.run(ExecutionThread.java:33)
Executing method [TC_2377154_12236]... completed
There is an issue while updating the script status to excel report. Please check file:null
Total:2
Passed:1  50%
Custom Report Generator is configured as: 
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : DONE - Custom Report Generator is configured as: 
 is not a valid CustomReportGenerator, it needs package.Class.method format and with two String args
TC_2377154_12236_Verify_SRS_ServerStatus_LinuxServer-TC_2377154_12236 : DONE -  is not a valid CustomReportGenerator, it needs package.Class.method format and with two String args

1 Ответ

0 голосов
/ 07 ноября 2019

Не извлекайте несколько элементов из цикла For Loop. Вы должны найти каждый элемент в цикле For Loop снова.

WebElement pag = diver.findElement (By.xpath ("(// a [@ style = 'color: Black;']) [" +(i + 1) + "]"));

Пример Xpath (вы можете искать в веб-консоли):

(// a [@ style = 'цвет: черный; ']) [1]

        List<WebElement> pagination = driver.findElements(By.xpath("//a[@style='color:Black;']"));

        int s = pagination.size()/2;
        System.out.println(s +"Pagination list");

        for(int i=0;i<=s;i++){
            // Add this line
            WebElement pag = diver.findElement(By.xpath("(//a[@style='color:Black;'])["+(i+1)+"]"));

            List<WebElement> ls = driver.findElements(By.xpath("//font[@color='red']"));
            System.out.println(ls.size()+"list of Down services size");
            if (ls.size() > 1)
                    Assert.fail("All service states are expected Up and Running but there are "+(ls.size()+" servers are down")); 
            else if (ls.size() == 0)
                Assert.fail("****Some technical issue or No Server is up or running****");
            else if (ls.size() == 1)
                Assert.pass("~~All Servers are Up and running~~");

                Thread.sleep(5000);

            //  ls.get(i).click();
             // Thread.sleep(5000);
             System.out.println( pagination.get(i)); 
             //driver.findElement(By.xpath("//a[@style='color:Black;']")).click();

             // Modify this line
             pag.click();

       Thread.sleep(5000);
    }
...