samedi 4 avril 2020

How to open multiple hyperlinks in a webpage contains same anchor text, using selenium python

I am using selenium python and want a program that checks the entire web page and opens all the hyperlinked text in a new tab containing same word. I make this program but this is opening only 1 link in a new tab. If I use "while" loop then it lopping the same link again and again in a new tab.

code

from selenium import webdriver
import time
from selenium.webdriver.common.keys import Keys
import re
from selenium.webdriver.common.action_chains import ActionChains

driver = webdriver.Chrome()
driver.maximize_window()
driver.get('https://en.wikipedia.org/wiki/Moon')
element = driver.find_element_by_link_text('natural satellite')

ActionChains(driver) \
        .key_down(Keys.CONTROL) \
        .click(element) \
        .key_up(Keys.CONTROL) \
        .perform()

when I use for loop it does not work either. The error is web element is not iterable. Please Help.




Aucun commentaire:

Enregistrer un commentaire