0

Problem : ScrollIntoView hiding element behind header/footer . My application is having header/footer .

Tried following solutions :

1) ScrollIntoView(true) , it hiding web element behind header if element is up and tried to scroll from bottom .

2) Sending true/false , it works , but I don't know exact location of element , so cant use every time to tell framework scroll down/up towards element .

3) Directly clicked ( taken action ) on element , chrome automatically scroll to visibility , but header is present that's why it hiding behind that .

Please let me know is there any single code that will make a element visible even it header/footer present .Looking solution is c# and using chrome browser .

Raks
  • 31
  • 6

2 Answers2

0

I have several suggestions to this:

  • Have you looked at the actions API, as described in this post (It is mainly targeted at Java, but the C# api is quite similar)
  • You might apply the following procedure:

    1. Scroll the element into view
    2. Find out if it is hiding behind the header or the footer
    3. Scroll it downward by the height of the header, or upward by the height of the footer.
  • You can fetch its absolute position in the page, and scroll to there.

AZWN
  • 158
  • 12
  • Thank you @AZWN for response , please can you tell me how you decide by code element is hiding behind header/footer to make up/downward to make visible . Please can you post the code . Please can you help me on this **You can fetch its absolute position in the page, and scroll to there.** – Raks Jun 03 '17 at 15:41
0

You can do that using Actions API.

  1. Check whether element is present.
  2. Move to element using Actions class.
  3. Check element is visible.
  4. If element is visible then perform action on element.

    By element = By.id("element_id");
    if(driver.findElements(element).size()>0){
        Actions action = new Actions(driver);
        action.moveToElement(driver.findElement(element).perform();
        if(driver.findElement(element).isDisplayed()){
            driver.findElement(element).click();
        }
    }
    
Ankur
  • 893
  • 3
  • 12
  • 29
  • Thanks for your response @Ankur , action API also gives same problem ( above explained ) if header/footer present .So you cant use this . I already tried . – Raks Jun 04 '17 at 18:37
  • Try with make element visible using JavaScriptExecuter and then perform action on this. Similar like this - JavascriptExecutor js = (JavascriptExecutor) driver; WebElement element = driver.findElement(By.id("element")); js.executeScript("arguments[0].setAttribute('style', 'z-index: -1')",element); – Ankur Jun 05 '17 at 04:36
  • the above code you pasted will not scrolls to element ( to make visible ) , so it will not work . – Raks Jun 07 '17 at 14:12