Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to click on the button which is present in the middle of the page

HTML code

<a href="" ng-click="select()" tab-heading-transclude="" class="ng-binding">RESUME</a>

Problem: After clicking on link in our application,page is opening in new tab. In that new page i have to click on the resume tab(It is in middle of the page).

I have to scroll down and click that tab but am not able to click.

My code:

browser.executeScript('window.scrollTo(0,250);');
element(by.partialLinkText("RESUME")).click(); 

please help me

like image 784
nrs Avatar asked Oct 08 '15 07:10

nrs


2 Answers

Switch to the new tab before even trying to click on the element. Later, wait until the element is present and is in clickable state using ExpectedConditions instance and elementToBeClickable() function in protractor. Once its in clickable state then perform a click() action. However click() function in protractor should scroll the page automatically without the need for you to scroll. Here's how -

browser.getAllWindowHandles().then(function(handles){
    browser.switchTo().window(handles[1]).then(function(){
        var elem = element(by.partialLinkText("RESUME"));
        browser.wait(protractor.ExpectedConditions.elementToBeClickable(elem), 10000)
        .then(function(){
            elem.click();
        });
    });
});

If the above code still doesn't click then do add in the scroll line before clicking it by resolving the promise that the functions return. Here's how -

var elem = element(by.partialLinkText("RESUME"));
browser.wait(protractor.ExpectedConditions.elementToBeClickable(elem), 10000)
.then(function(){
    elem.getLocation().then(function(loc){
        browser.executeScript('window.scrollTo('+loc.x+','+loc.y+');').then(function(){
            elem.click();
        });
    });
});

Hope it helps.

like image 134
giri-sh Avatar answered Oct 21 '22 02:10

giri-sh


"After clicking on link in our application,page is opening in new tab".... New Tab of browser? Switch to the new tab first. Then click on that button. Try browser.getWindowHandles(). It will return you a set.

like image 40
asu Avatar answered Oct 21 '22 02:10

asu