Issue
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 class="logonRow" id="_id0:logon:USERNAME:row">
<div class="logonLabel">
<label for="_id0:logon:USERNAME">User Name:</label>
</div>
<div class="logonInput">
<input type="text" id="_id0:logon:USERNAME" name="_id0:logon:USERNAME">
</div>
Solution
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.
Answered By - Ivan
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.