How to open links in new tab in chrome browser

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
uniadv
Junior Coder
Posts: 26
Joined: Tue Aug 04, 2020 2:16 am

How to open links in new tab in chrome browser

Post by uniadv » Thu Nov 05, 2020 8:17 am

Hi Team,
I have two questions.
First: There is a webpage where i have to click on "Load More" button in order to load more results on the same page. The button is keep on visible until there is no more results to load are availiable. I use Xpath to click on "Load More" element in Chrome. How to identify if there is "Load More" element is availiable or not.

Second: After every result loads up, i need to open each link in the new tab to perform some task and close it and come back to result page to open next link. How to open links in new tab and switch to new tab and close it and return to previous tab. I use Chrome Browser & Xpath.

Reagrds,
Ushahra

User avatar
Marcus Tettmar
Site Admin
Posts: 7281
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Re: How to open links in new tab in chrome browser

Post by Marcus Tettmar » Fri Nov 06, 2020 4:41 pm

First: Just using FindElement to find the element should be enough - if it's not found then you'll get back zero results.

Second: If it's a link can you extract it using ChromeGetElementData and then navigate to it? Also do you really need to open it in a new tab? Can't you just 'click' it and then navigate back when done? Otherwise you could use image recognition to find the button and then issue a right click and choose from the context menu.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
uniadv
Junior Coder
Posts: 26
Joined: Tue Aug 04, 2020 2:16 am

Re: How to open links in new tab in chrome browser

Post by uniadv » Mon Nov 09, 2020 9:47 am

Hi,
Here i need to open links in new tab because by default the webpage show 20 results, on clicking "Load More" for 15 times, it loads up around 300 results. If i open the links in the same tab and again go back to previous page, it shows only default 20 results, here again i have to load all the links. Also loading more result on each click takes around 3-4 seconds which eventually increase the time if i keep on navigating back & forth.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 748
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How to open links in new tab in chrome browser

Post by Dorian (MJT support) » Mon Nov 09, 2020 10:22 am

In that case Image Recognition would fit the bill here.
Yes, we have a Custom Scripting Service. Message me or go here

User avatar
uniadv
Junior Coder
Posts: 26
Joined: Tue Aug 04, 2020 2:16 am

Re: How to open links in new tab in chrome browser

Post by uniadv » Mon Nov 09, 2020 10:49 am

I have an idea, what if i can store all the links to a temporary notepad file and then open the link one after another to perform task? I think that would work. How can i achieve that? I mean how to send the data to notepad file in each new line and once its done, how to extract the link one by one? Any reference would help!

User avatar
uniadv
Junior Coder
Posts: 26
Joined: Tue Aug 04, 2020 2:16 am

Re: How to open links in new tab in chrome browser

Post by uniadv » Mon Nov 09, 2020 12:50 pm

I used the above method of storing data in notepad and then opening it one by one and it worked! :D
I have created an empty notepad file in some directory and using it to storing and fetching the link.

Code: Select all

  //Finding the total number of result for running the loop
  ChromeFindElements>s1,xpath,/html/body/div[5]/div[1]/div[2]/div,result


//Loop to get the links in notepad

let>p=0
Repeat>p
let>p=p+1

  ChromeFindElements>s1,xpath,/html/body/div[5]/div[1]/div[2]/div[%p%]/a,link
  ChromeGetElementData>s1,link_1,attribute/href,strResult
  WriteLn>C:\Users\user\desktop\sample.txt,nWLNRes,%strResult%
  
Until>p=%result_count%

//Loop to open every link in chrome

let>p=0
Repeat>p
let>p=p+1

  ReadLn>C:\Users\user\desktop\sample.txt,%p%,strLine
  ChromeNavigate>s1,url,%strLine%
  //Running Some Task

Until>p=%result_count%

But again i'm having a issue. Each time i have to clean up the notepad file whenever i run the script. Is there any alternative to it? Like deleting & recreating the file or cleaning up the data from the notepad each time while running the script.

User avatar
Dorian (MJT support)
Automation Wizard
Posts: 748
Joined: Sun Nov 03, 2002 3:19 am
Contact:

Re: How to open links in new tab in chrome browser

Post by Dorian (MJT support) » Mon Nov 09, 2020 1:12 pm

I was just in the process of trying to create something like that for you. Nice work thinking outside the box. :D

Yes, you can use DeleteFile before the loop containing WriteLn.
Yes, we have a Custom Scripting Service. Message me or go here

user5274
Junior Coder
Posts: 23
Joined: Tue Aug 04, 2020 9:35 am

Re: How to open links in new tab in chrome browser

Post by user5274 » Sun Nov 15, 2020 8:04 pm

it is a happy sight to see owners solve their own problems as in this case. Great job solving the problem.

Although, id be negligent in not offering a tip, instead of using notepad (*.txt) why not use internal MS15 arrays to store the data. this way you dont need to find a spot for the "C:\Users\user\desktop\sample.txt", research MS15 arrays in the help manual for help

for example, since you already know the %result_count% you can dimension an array of the proper size

Code: Select all

ArrayDim>BADASSLINKS,result_count,string
Then you can refer to them as

Code: Select all

BADASSLINKS_%P%

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts