I am trying to fill a webelement with Selenium but can't 'reach' it. This is the code I am going to use:
Dim driver As New webdriver
driver.Start "Chrome"
driver.get "https://example.com"
'driver.FindElementByClass("gn_sdm_header_background").FindElementByName("searchKey").SendKeys ("abcd")
'driver.FindElementByCss("#gobtnDiv > form > table > tbody > tr > td:nth-child(3) > input[type=text]").SendKeys ("abcd")
'driver.FindElementByXPath("//*[@id=""gobtnDiv""]/form/table/tbody/tr/td[3]/input").SendKeys ("abcd")
End Sub
All the lines above resulted NoSuchElementError
Element not found for...
- line: class=gn_sdm_header_background
- line: Css= #gobtnDiv > form > table > tbody > tr > td:nth-child(3) > input[type=text]
- line: XPath=//*[@id="gobtnDiv"]/form/table/tbody/tr/td[3]/input
And here are the parameters of the field: Printscreen of element-inspection
I have no idea how to do it, so any help is greatly appreciated!!
CodePudding user response:
The input
element is inside an iframe
. you need to switch to iframe
first, in order to access the input element.
driver.SwitchToFrame .FindElementByXPath("//iframe[@name='gobtn']", timeout:=10000)
driver.FindElementByXPath("//input[@name='searchKey']").SendKeys ("Test")