1

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/')]")))

1 Answer 1

1

check the time it takes for the new h3 tag to be available in DOM after hovering event.

May find_element_by_xpath is fired before the new h3 tag is created, if that the case you may want to dynamically wait for the new h3 tag

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks and I added a dynamic wait statement, which solves the problem partially.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.