Hi im trying to insert a username in a text field but it wont let me get the Xpath this si mi code hope you can help me solving this error:
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
s=Service('webdriver//chromedriver.exe')
driver = webdriver.Chrome(service = s)
driver.get('http://190.109.11.66:8888/BOE/BI')
element = driver.find_element(By.XPATH,'//*[@id="_id0:logon:USERNAME"]')
element.send_keys("dbayona")
this is the error that im getting:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="_id0:logon:USERNAME"]"}
a ss of the html pagr: Html ss web page
HTML part where im trying to get the Xpath of Username
</div>
<div id="_id0:logon:USERNAME:row">
<div >
<label for="_id0:logon:USERNAME">User Name:</label>
</div>
<div >
<input type="text" id="_id0:logon:USERNAME" name="_id0:logon:USERNAME">
</div>
CodePudding user response:
You can't find element because it is inside iframe. It is essentially a document within a document. To search in it, you must first switch to it.
driver.get('http://190.109.11.66:8888/BOE/BI')
iframe = driver.find_element(By.NAME, "servletBridgeIframe") # Your iframe
driver.switch_to.frame(iframe)
element = driver.find_element(By.XPATH, '//*[@id="_id0:logon:USERNAME"]')
element.send_keys("dbayona")
driver.switch_to.default_content() # If you want switch back to your document.