J R
J R

Reputation: 175

Selenium Python using ActionChains

enter image description hereThe code I have opens a website and using actionChains, it right clicks on the desktop which brings up a menu. I now need to do 3 more things with actionChains. I need to hover over the item that says Save Page WE and then click an item on the sub-menu that pops up and then hit the enter button. Can anyone show me how to do this? Thanks

from selenium import webdriver

    from selenium.webdriver import ActionChains
    fp = webdriver.FirefoxProfile('/Users/Jake/AppData/Roaming/Mozilla/Firefox/Profiles/emjx467y.default-1524932841911')
    driver = webdriv[enter link description here][1]er.Firefox(fp)
    driver.get('http://www.tradingview.com/screener')
    element = driver.find_element_by_link_text('Screener')
    actionChains = ActionChains(driver)
    actionChains.context_click(element).perform()

Upvotes: 0

Views: 17234

Answers (1)

cruisepandey
cruisepandey

Reputation: 29362

By using this line : actionChains.context_click(element).perform() , you are trying to right click on Screener menu. But the ideal behavior should be to be hover on it and select one options out of 3.

I'm selecting Forex Screener, you can select any one as per your requirement.

For hover over you can try this code :

actionChains.move_to_element(element).perform()  

Full code would be like this :

driver.get("http://www.tradingview.com/screener")  
wait = WebDriverWait(driver,40)

driver.find_element_by_css_selector("span[class*='tv-header__dropdown-wrap--noarrow'] span[class$='lang-icon--current-lang']").click()
wait.until(EC.element_to_be_clickable((By.XPATH, "//span[text()='English (UK)']/parent::a"))).click()
element = driver.find_element_by_link_text('Screener')
actionChains = ActionChains(driver)
actionChains.move_to_element(element).perform()

wait.until(EC.element_to_be_clickable((By.LINK_TEXT, "Forex Screener"))).click()  

Make sure to import these :

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC 
from selenium.webdriver.common.action_chains import ActionChains

Upvotes: 1

Related Questions