Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

183
Views
How is chrome made to ignore javascript and how to overcome this?

Some website respond to javascript instructions and some do not. Santanders website allows javascript on the very front page but once you try to log in things change. the following passed in from python will print to console on the front page but not the second page.

driver.execute_script('console.log(" lll kkk cheaky breeki ");')

i can still just open up the developer tools and type

console.log(" lll kkk cheaky breeki ");

and it still works when i do it manually, but not when passed in by python.

my full script is below

import time
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import selenium.common.exceptions as s_ex

driver = webdriver.Chrome("chromedriver.exe")
driver.get("https://www.santander.co.uk/")
login_xp = '/html/body/div[3]/header/div[1]/div/nav/div/div[1]/div/div/nav/ul/li[2]/a';
time.sleep(1)
driver.execute_script('console.log(" i print fine  ");')
WebDriverWait(driver,10).until(EC.presence_of_element_located((By.XPATH,login_xp)))
log = driver.find_element_by_xpath(login_xp)
log.click();
time.sleep(2)
driver.execute_script('console.log(" lll kkk cheaky breeki ");')  ## how can i get this to print, why doesnt it now?
  1. how do i make this page accept js?
  2. why does it not accept js now?
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

I've tried your example - it looks like the line log.click() makes the browser open a new tab. When that happens, your driver is still pointing at the original tab with the homepage.

Running driver.execute_script('console.log(" lll kkk cheaky breeki ");') at this point will execute the script in the original tab, not in the new one.

If you want to run a script on the log in page, I'd suggest going there directly using, for example:

driver.get('https://retail.santander.co.uk/olb/app/logon/access/#/logon')
about 4 years ago · Juan Pablo Isaza Report

0

The problem is that log.click() opens a new tab. So you need to tell the driver to switch to that new tab and execute all statements on that tab from now on. You will find that currently the driver also can't find any elements on the new tab as it still looking at your old tab.

log.click()
driver.switch_to.window(driver.window_handles[-1])
driver.execute_script('console.log(" lll kkk cheaky breeki ");')

Note that the tab switching is quite rudimentary, it simply goes to the last tab.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!