Issue
So I have a Copy Link button at the system I'm testing, and that works. means if I paste it manually (ctrl+v) to the browser's url line , it's ok. But when I try using Keys nothing happens.
I need to OPEN a new tab, NAVIGATE to it, DELETE the about:blank (from the browser's url line), PASTE the URL, (that's already been copied), and press ENTER
Here is the code: 1)I open a new tab 2)I navigate to the tab
the first 2 actions work well. the rest don't seem to work for some reason (from this line: action.key_down(Keys.CONTROL).send_keys('a').perform() )
Code:
self.driver.execute_script('''window.open("","");''')
action = ActionChains(self.driver)
profile_window = self.driver.window_handles[1]
self.driver.switch_to.window(profile_window)
action.key_down(Keys.CONTROL).send_keys('a').perform()
action.send_keys(Keys.DELETE).perform()
action.send_keys(Keys.CONTROL).send_keys('v').perform()
action.key_up(Keys.CONTROL).perform()
action.send_keys(Keys.ENTER)
Solution
Update 1 :
driver.get("https://www.google.com")
driver.execute_script("window.open('about:blank','_blank');")
all_handles = driver.window_handles
driver.switch_to.window(all_handles[1])
driver.get("https://www.amazon.com")
Update 2 :
You can use pyperclip
to paste
as well. see below
import pyperclip
action = ActionChains(driver)
action.send_keys(pyperclip.paste()).perform()
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.