1

I have my code working on selenium but the problem is that when the code is running I can't switch to another chrome windows because it will send keybord key to the new one. I need to send the key only to a specific windows where the code is running

driver = webdriver.Chrome('chromedriver')
driver.get ("mywebsite link")
        

        sleep(1)
        keyboard.send('l')
        sleep(0.5)
        keyboard.send('t')
        sleep(0.5)
        keyboard.send('enter')
        time.sleep(0.5)
    
  • what is keyboard.send? – PDHide Mar 15 '21 at 20:40
  • when you are on twitter you can click l for like and t for retweet –  Mar 15 '21 at 20:50
  • Does this answer your question? [How to switch to new window in Selenium for Python?](https://stackoverflow.com/questions/10629815/how-to-switch-to-new-window-in-selenium-for-python) – kevinvi8 Mar 15 '21 at 20:53
  • No basically, I don't need to switch the windows I want to execute my keyboard key to windows I have open only, because if I open a notepad for example it will send key to the notepad –  Mar 15 '21 at 20:56

1 Answers1

0

So I had a similar issue to this a while back. The issue that you are running into is that you need to make sure that you are working with the correct window handle.

Your answer should be pretty easily solved here: How to switch to new window in Selenium for Python?

kevinvi8
  • 191
  • 1
  • 10