-1

Webdriver seems to not able to pick webelement (button) on a page which it located initially but coming back to same page on traversing multiple pages, same object doesn't get located by selenium webdriver.

Situation is like, I'm at home page and verified it by adding .isDisplayed()method like this-

if (isElementPresent("(//input[@name='sbqq__editlines'])[1]") == true)
{
    System.out.println("YES, reached on Quote page");
    if (objApprovalBlk.findElement(By.xpath(".//table[@class='list']")).isDisplayed())
        {
        List<WebElement> rows = objApprovalBlk.findElement(By.xpath(".//table[@class='list']")).findElements(By.xpath(".//tr"));
        List<WebElement> rows = objApprovalBlk.findElement(By.xpath(".//table[@class='list']")).findElements(By.xpath(".//tr"));

...now if rows are present with text 'Requested' then a link has to be clicked on that row and workflow takes the user to multiple page of Apporval !


driver.findElement(By.xpath("//input[@value='Approve']")).click();

///Reaching back to QUOTE page now !            ---NOT WORKING FROM HERE !
    tmpElement = new WebDriverWait(driver, 100)
                .until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='sbqq__editlines'])[1]")));
    tmpElement = null;

}else{
        System.out.println("Didn't reached Quote Page !");
    }

So,on reaching back to home page, same object //input[@name='sbqq__editlines'])[1] is not identifiable. Following is the exception I'm receiving :

org.openqa.selenium.TimeoutException: Timed out after 100 seconds waiting for element to be clickable: By.xpath: //input[@name='sbqq__editlines'])[1]

I'm not able to understand the issue behind this, does driver referring a stale object or when I clicked the link on Quote home page, it was not from driver object directly but something else and hence I might need to refresh driver object. I've just started with selenium while coming from HP UFT background hence that thought of refreshing object was my first assessment of the issue.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • is it a pagination link? – shank087 Feb 02 '17 at 06:13
  • Try using isElementPresent("(//input[@name='sbqq__editlines'])[1]") before using tmpElement. Check whether your element is visible. – peter pawar Feb 02 '17 at 07:31
  • No, not a pagination link but think of request - approvals page, where links to provide approvals are there ! So I need to click the available links one by one to provide the approvals and after each approval, control come back to the main page ! – irahulsingh Feb 02 '17 at 08:01
  • @peterpawar, sure let me try and update. But mean while, any reason to use 'isElementPresent' before ? I'm using that condition as SYNC so that home page get opened comfortably first before proceeding any further ! – irahulsingh Feb 02 '17 at 08:04
  • meanwhile, Thanks @Narendra Rajput for the editing/formatting of the question. – irahulsingh Feb 02 '17 at 08:07
  • @Narendra - regarding your edit, we would prefer proper nouns not to be code formatted. Selenium, for example, just needs a cap letter, since the word itself is not code. Same with HP. Thanks. – halfer Feb 02 '17 at 09:14
  • 1
    thanks @halfer for the insight on formatting (atleast to me) ! – irahulsingh Feb 02 '17 at 09:33

1 Answers1

0

As per this answer :

try using

  PageFactory.initElements(driver, this);

just before performing any activities on base page.

Community
  • 1
  • 1
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46
  • Thanks @Kushal for the reply. POM is still needs to be implemented in my code, but can you share the reason of sharing this method. Can we assume driver needs to be initialized (or refreshed) with latest values even when we have just landed on a page and trying to wait for the page to get loaded completely by : `tmpElement = new WebDriverWait(driver, 100) .until(ExpectedConditions.elementToBeClickable(By.xpath("//input[@name='sbqq__editlines'])[1]"))); ` Let me know if there is something i might be missing. – irahulsingh Feb 02 '17 at 14:12