How to delete an element from a webpage in chrome

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

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

How to delete an element from a webpage in chrome

Post by uniadv » Thu Jan 21, 2021 3:54 am

Hello Team,

I'm facing an issue. While scraping the data from a website, few elements like pop-ups, some promotional ads etc. are breaking the script which is making scraping harder. Earlier I've used to xpath to close the pop-ups but again the in-line promotional ads & irrelevant element are messing up with the script. I figured out if I delete the elements before itself from the chrome's inspect element while pausing the script using "Messagemodal", it solves the problem. I would like to know how to delete the certain elements like this directly using the script. An example would be great for help.

Regards,
Ushahra

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

Re: How to delete an element from a webpage in chrome

Post by uniadv » Thu Jan 21, 2021 12:32 pm

Hi Team,
I have figured out a way, I injected JS code to Chrome console to remove the irrelevant element using following code.

Code: Select all

GoSub>ExecuteJS,s1,document.getElementById("reactExitIntent").remove();
Its Subroutine program:

Code: Select all

SRT>ExecuteJS
  Let>HTTP_POSTJSON=1
  Let>body= { "script": "%ExecuteJS_Var_2%", "args": [] }
  //if you are not using the standard port and have changed it with CHROMEDRIVER_PORT then change the port number here accordingly
  HTTPRequest>http://localhost:9515/session/%ExecuteJS_Var_1%/execute,,POST,body,theResult
END>ExecuteJS
Its working perfectly fine.

Thanks & Regards

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

Re: How to delete an element from a webpage in chrome

Post by uniadv » Thu Jan 21, 2021 12:39 pm

I have another issue if anyone can help.

During the webpage scrapping on Chrome browser, there are few popups (in-page popup) which doesn't show up until I navigate on the pages for 30-40 seconds. When it shows up in the middle of the task, the script starts giving blank values instead of the actual data. I couldn't wait for the popup to show up and then close it in order to start scrapping.

Can anyone help me with this, how to either block the popups before stating the script or identify the when popup appears so the script automatically close it & move further?

Thanks!

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