0

I am trying to use Selenium with PowerShell. I have to capture a search button, but i am not able to do so. The element needs to be captured is

<a id="btnAdvSearchMenu" class="searchbox-btn" href="/AdvancedSearch.aspx" style="display: none;"></a>

I have the html as: enter image description here

When i hover the search option, it takes me to "btnAdvSearchMenu" tag.

I am using below PowerShell code to capture this. Please suggest if i am missing something.

$ChromeDriver.FindElementByClassName("searchbox-btn").click()
Prophet
  • 32,350
  • 22
  • 54
  • 79
SA.
  • 732
  • 7
  • 20
  • 38

1 Answers1

2

You are trying to click invisible element. In the element XML you shared you can see style="display: none;".
Selenium imitates real user GUI actions. As a user you normally can't click invisible elements.
Also, there may be more problems with you code that we can't see since you shared only this information.
UPD
The updated XML shows that the element you trying to access is inside the iframe. In order to access elements inside iframe you need to switch driver to that iframe. Also, when finished and you will want to access elements out of that iframe block you will need to switch to the default content.
I know how to do that with normal languages like Python and Java but not a Powershell, I'm sorry. But I'm sure you can find examples for that here in Stackoverflow.

Prophet
  • 32,350
  • 22
  • 54
  • 79
  • updated the ques with more info – SA. Aug 10 '22 at 16:03
  • @kawade see the updated answer – Prophet Aug 10 '22 at 17:26
  • Please let me know how to do that using python/Java, i will get an idea and will try to implement in PowerShell – SA. Aug 11 '22 at 08:28
  • 1
    You can simply google that with something like "selenium switch to iframe" it will give you a lot of examples like this https://stackoverflow.com/questions/44834358/switch-to-an-iframe-through-selenium-and-python or this https://stackoverflow.com/questions/10879206/how-to-switch-between-frames-in-selenium-webdriver-using-java and much more – Prophet Aug 11 '22 at 08:46
  • Thanks Buddy. i tried something like $ChromeDriver.SwitchTo().Frame(2); $ChromeDriver.FindElementByClassName("searchbox").SendKeys("test"); but getting error as Exception calling "FindElementByClassName" with "1" argument(s): "no such element: Unable to locate element: {"method":"css selector","selector":".searchbox"} (Session info: chrome=104.0.5112.81)" – SA. Aug 11 '22 at 14:01
  • I think here `$ChromeDriver.SwitchTo().Frame(2);` it should be a locator passed to `Frame()` method, not an integer 2 – Prophet Aug 11 '22 at 14:05
  • Thanks Buddy. I rectified the issue, I was calling the wrong iframe. – SA. Aug 16 '22 at 12:14