Created
July 20, 2018 15:20
-
-
Save prakritidev/569524b40ed87d174fcaeabbb4d11eb4 to your computer and use it in GitHub Desktop.
Open link in new tab using selenium python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from selenium import webdriver | |
from selenium.webdriver.common.keys import Keys | |
from selenium.webdriver.common.action_chains import ActionChains | |
import time | |
driver = webdriver.Chrome("drivers/chromedriver") | |
try: | |
driver.get("http://www.google.com") | |
input_element = driver.find_element_by_name("q") | |
input_element.send_keys("fuck you") | |
input_element.submit() | |
link = driver.find_element_by_xpath( | |
'//*[@id="rso"]/div[1]/div/div[2]/div/div/h3/a').click() | |
# for windows change command to control. | |
ActionChains(driver).move_to_element(link).key_down(Keys.COMMAND).click(link).key_up(Keys.COMMAND).perform() | |
time.sleep(5) | |
except Exception as e: | |
print(e) | |
driver.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
try this one
https://github.com/MohamedMesto/Statistical-Analysis-and-Engineering-Acoustics-Py/tree/main/examples