Reputation: 11
I have problem with finding element on login page. I need to test login procedure. Web page where I have problem is part of SAP Business Object platform so it's not world wide. There is strange naming convention and I cannot send keys to user and password input element. It looks like this:
<div class="logonRow" id="_id0:logon:USERNAME:row">
<div class="logonLabel">
<label for="_id0:logon:USERNAME">Nazwa użytkownika:</label>
</div>
<div class="logonInput">
<input type="text" id="_id0:logon:USERNAME" name="_id0:logon:USERNAME" value="">
</div>
I'm using below java code. I tested it on other pages and it's working fine.
WebElement loginName = wd.findElement(By.name("_id0:logon:USERNAME"));
loginName.clear();
loginName.sendKeys(userName);
I will much appreciate advises.
PS.
I tried this with no luck:
WebElement loginName = wd.findElement(By.id("_id0:logon:USERNAME"));
WebElement loginName = wd.findElement(By.xpath("//*[@id='_id0:logon:USERNAME']"));
WebElement loginName = wd.findElement(By.cssSelector("label[for='_id0:logon:USERNAME']"));
WebElement loginName = wd.findElement(By.xpath("//label[@for='_id0:logon:USERNAME']"));
Here is error I receive:
org.openqa.selenium.NoSuchElementException: Unable to locate element: label[for='_id0:logon:USERNAME']
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'ROBERTTEST', ip: '10.5.241.54', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_191'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities {acceptInsecureCerts: true, browserName: firefox, browserVersion: 63.0.3, javascriptEnabled: true, moz:accessibilityChecks: false, moz:geckodriverVersion: 0.23.0, moz:headless: false, moz:processID: 2792, moz:profile: C:\Users\mardudek\AppData\L..., moz:useNonSpecCompliantPointerOrigin: false, moz:webdriverClick: true, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, platformVersion: 10.0, rotatable: false, setWindowRect: true, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify}
Session ID: 85cf59e4-eb21-4ec5-a2b3-afd0a0e6f956
Here is web page I saved: https://ufile.io/dqvbh
Upvotes: 0
Views: 872
Reputation: 11
There was iframe in the page. First I to switched to iframe and then I found my element.
Upvotes: 1
Reputation: 193058
As per the HTML you have shared to send a character sequence to the USERNAME field you can use either of the following solutions:
cssSelector:
WebElement loginName = wd.findElement(By.cssSelector("label[for='_id0:logon:USERNAME']"));
loginName.clear();
loginName.sendKeys(userName);
xpath:
WebElement loginName = wd.findElement(By.xpath("//label[@for='_id0:logon:USERNAME']"));
loginName.clear();
loginName.sendKeys(userName);
Upvotes: 0
Reputation: 31
maybe you should try to get the element by ID.
Try one of these:
WebElement loginName = wd.findElement(By.ID("_id0:logon:USERNAME"));
WebElement loginName = wd.findElement(By.xpath("//*[@id='_id0:logon:USERNAME']"));
Upvotes: 0