In my current project, I am using Selenium in C# to run a task in Chrome. The task involves keeping the first/main tab open and opening multiple new tabs for various operations. On each execution of the task, this process repeats around 15-20 times.
I have experimented with different methods to open a new tab, such as SendKeys, but none of them were effective except for injecting the provided JavaScript code into the webdriver.
var d=document,a=d.createElement('a');a.target='_blank';a.href='';a.innerHTML='.';d.body.appendChild(a);return a;
However, every time a new tab is opened, the first/main tab scrolls to the bottom before the new tab appears. This scrolling behavior causes issues because the web page in the first/main tab loads additional content due to scrolling.
My main concern is understanding why the JS code results in scrolling to the bottom of the first/main tab and finding a solution to prevent it from happening.