0

I want to send a string to the web page whose text field name is "inputfield". Actually, I can send the word to the page, but when I run the program, a new "chrome" page opens, which is used for testing purposes. However, I want to send a string to the field on a chrome page that is already open.

Here my code:

from selenium import webdriver
import time

url = "https://10fastfingers.com/typing-test/turkish"
options = webdriver.ChromeOptions()
options.binary_location = r"C://Program Files//Google//Chrome//Application//chrome.exe"
chrome_driver_binary = 'chromedriver.exe'
options.add_argument('headless')
driver = webdriver.Chrome(chrome_driver_binary, options=options)
driver.get(url)

driver.implicitly_wait(10)

text_area = driver.find_element_by_id('inputfield')
text_area.send_keys("Hello")

Nothing happens when I run this code. Can you please help? Can you run it by putting a sample web page in the url part?

Thank you.

EDIT: It is working when I deleted options. But still opening a new page when I run it. Is there a way use a page which already open on background.

chrome_driver_binary = 'chromedriver.exe'
driver = webdriver.Chrome(chrome_driver_binary)
driver.get('https://10fastfingers.com/typing-test/turkish')

text_area = driver.find_element_by_id('inputfield')
text_area.send_keys("Hello")

2 Answers 2

1

Click the popup prior to sending keys.

driver.get('https://10fastfingers.com/typing-test/turkish')
wait=WebDriverWait(driver, 10)
wait.until(EC.element_to_be_clickable((By.ID, "CybotCookiebotDialogBodyLevelButtonLevelOptinAllowallSelectionWrapper"))).click()
text_area = wait.until(EC.element_to_be_clickable((By.ID, "inputfield")))
text_area.send_keys("Hello")

Imports

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. I solved my problem with similar solution.
0

I am not sure what is your question but if the issue is multiple tabs or windows being opened then:

you can switch between the windows as:

// you can move to specific handle    
chwd = driver.window_handles
print(chwd)
driver.switch_to.window(chwd[-1])

you should shoul switch to the correct window before you can interact with elements on that window

just switch to the window that was already opened bypassing the index

If the problem is that you want to interact with an already opened chrome then you should follow below steps:

Start chrome with debug port:

<path>\chrome.exe" --remote-debugging-port=1559

Python :

from selenium import webdriver
from selenium.webdriver.chrome.options import Options

chrome_options = Options()
chrome_options.add_experimental_option("debuggerAddress", "127.0.0.1:1559")
driver = webdriver.Chrome(options=chrome_options)

1 Comment

It is not my problem but I can use this method for another project. Thanks for your help.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.