I am trying to locate an element (a h3 tag which only shows up by hovering onto it). After some search, it seems like ActionChains in selenium is the way to go. The code has two steps: 1: locate the mouseover object and hovering onto it. step 2: locate the new appread h3 tag. So far, Step 1 is fine. But I got Unable to locate element: error for Step 2. For to mention, the appeared item an iframe object. Any suggestions are appreciated.
### Step 1: locate the mouseover object
each_username_h = review_block_html.find_element_by_xpath('.//div[starts-with(@class, "username")]')
Hover = ActionChains(driver).move_to_element(each_username_h)
Hover.perform()
### Step 2: locate new h3 tag
user_hyper_link = driver.find_element_by_xpath('.//h3[starts-with(@class, "username")]')
Update (solved)
It seems like I need to click the hovered item. Then I also added a dynamic waiting item (thanks to michael satish) which makes sure to locate item when it is available.
### Step 1: locate the mouseover object
each_username_h = review_block_html.find_element_by_xpath('.//div[starts-with(@class, "username")]')
Hover = ActionChains(driver).move_to_element(each_username_h)
Hover.perform()
### Step 1.5: click the item
each_username_h.click()
### Step 2: locate new h3 tag
user_hyper_link = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.XPATH, "//a[starts-with(@href, '/members/')]")))