-1

I am trying to select a group from the search bar. Any tips on how to make element visible?

driver.findElement(By.xpath("//div[@id='global-search-box-item-0']")).click();

Below is the HTML structure.

<div role="option" id="global-search-box-item-0"><i aria-hidden="true" 
class="comments outline circular icon _2BaEJYulOrH2_i6ZYf-DdV" xpath="1" 
style=""></i><div class="_58oiWFV24V4GmIFrAnwPx"><div class="title">**Test 
Automation** HE Community PRIVATE Group</div><div class="description">**Test 
Automation** HE Community PRIVATE Group </div></div></div>>
4
  • 1
    Possible duplicate of Selenium Webdriver - click on hidden elements Commented Jun 6, 2018 at 13:11
  • Please show HTML and a screenshot to illustrate which element you want to select. If your app has public access URL, please give it too. Commented Jun 6, 2018 at 13:13
  • Please show some piece of code. Commented Jun 6, 2018 at 13:24
  • May be you have a duplicate xpath, please do double check. Commented Jun 7, 2018 at 12:40

1 Answer 1

0

If it's not visible, then the page logic should be changed to make it visible, if that's what you want?

You could hack your way around it with a javascript executor.

WebElement webElement = driver.findElement(By.xpath("//div[@id='global-search-box-item-0']"));

((JavascriptExecutor)driver).executeAsyncScript("args[0].style.display='block';",webElement);

Or else if it exists on the page and is visible, then this xpath would only return you the visible version of the element.

driver.findElement(By.xpath("//div[@id='global-search-box-item-0' and not(ancestor::*[contains(@style, 'display: none')])]")).click();
Sign up to request clarification or add additional context in comments.

Comments

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.