1

I'd like to change the time.sleep(8) to wait until I either click enter or click on a button using selenium. Like an input, but I don't want to write it in the python console, I instead want to press enter on the specific website.

time.sleep(8)
    skicka = driver.find_element_by_xpath("//body/div[4]/div[3]/div[1]/div[1]/div[1]/form[1]/div[4]/div[1]/div[1]")
    skicka.click()
Simmelari
  • 9
  • 2
  • What do you mean? Do you mean you want to have a web page where there would be a button by pressing which you could pause and resume your selenium script running somewhere else? – Alexey R. Mar 05 '21 at 16:28

2 Answers2

0
import time
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from time import sleep
from selenium import webdriver

import json
from selenium import webdriver
driver = webdriver.Chrome()
driver.get('http://example.com/')

body=driver.find_element_by_tag_name('body')

driver.execute_script('''var script = document.createElement("script");

var button = document.createElement("button")
button.setAttribute("type", "button");
button.setAttribute("id", "seleniumbutton");
button.setAttribute("onClick", "myFunction()");
button.textContent="Click me to continue selenium";

script.setAttribute("id", "seleniumscript");
script.textContent=`function myFunction() {

  alert("You pressed a key inside the input field");
      document.querySelector("#seleniumbutton").remove();
  document.querySelector("#seleniumscript").remove();

}`;



arguments[0].appendChild(button);
arguments[0].appendChild(script);

''',body)

WebDriverWait(driver,1000000000000000).until(EC.alert_is_present())
driver.switch_to_alert().accept()

input("Completed")

you can add an alert and button to the website and then wait for it . See the example. Here unless you click the button it won't execute your script

PDHide
  • 18,113
  • 2
  • 31
  • 46
0

You can use a python method to check for a key press input. this might help you?