-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>>
Vinit Mehta
  • 449
  • 4
  • 13
urlflo
  • 11
  • 4

1 Answers1

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();
TomH
  • 2,581
  • 1
  • 15
  • 30