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
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.
"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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With