Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

189
Visualizações
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 Respostas
Responde à pergunta

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 Relatório

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda