I need to open a webpage and send a keypress event (ctrl + f
) which will move the focus to a text box inside the webpage. Then I need to send a string to that text box.
I have two problems:
- The
ctrl + f
key press event does not work. - I am not able to locate the element in focus which is a text box element or send a string to that field.
This is the code I am trying:
self.driver = self.get_driver()
actions = ActionChains(self.driver)
actions.key_down(Keys.CONTROL).send_keys('f').key_up(Keys.CONTROL).perform()
editable = self.driver.execute_script("return document.activeElement")
print(editable.text)
editable.sendKeys("foo")
The solution in the other question did not solve my issue. I have provided the solution that worked for me, which is different from the way it works in Java version.