This is the html code of the page. I need to input some text in username field.
How do i do it ?
<div class="login_cred">
<label>Username*</label>
<input id="username" name="userName" tabindex="12" size="30" maxlength="30"
onfocus="getFocus(this.id);" autocomplete="off" oncopy="return false"
onpaste="return false" onkeypress="return disableCtrlKeyCombination(event);"
onkeydown="return disableCtrlKeyCombination(event);" type="text">
<label>Password*</label>
<input id="label2" name="password" tabindex="13" title="password" size="30"
onfocus="getFocus(this.id);" autocomplete="off" oncopy="return false"
onpaste="return false" onkeypress="return disableCtrlKeyCombination(event);"
onkeydown="return disableCtrlKeyCombination(event);" type="password">
<br>
<br>
I tried following code and it is giving an error saying element not found
driver.findElement(By.xpath("//input[#id='username']")).sendKeys("qa");
Try below :-
driver.get("https://retail.onlinesbi.com/retail/login.htm");
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.findElement(By.xpath("(//a[contains(.,'CONTINUE TO LOGIN')])[2]")).click();
driver.findElement(By.xpath("//input[#id='username']")).sendKeys("test");
Full code :-
System.setProperty("webdriver.gecko.driver", "D:\\Workspace\\FluentWaitTest\\src\\lib\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("https://retail.onlinesbi.com/retail/login.htm");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
driver.findElement(By.xpath("(//a[contains(.,'CONTINUE TO LOGIN')])[2]")).click();
driver.findElement(By.xpath("//input[#id='username']")).sendKeys("test");
If still not work then their can be some frame or other tag present which same attributes
This may be due to the cause that the element are not loaded when you are trying to open the url http://retail.onlinesbi.com/retail/login.htm. You have to click CONTINUE TO LOGIN button first then you get your input boxes.
Related
I need to print value of a disabled text box. The below given is the source code
<div class="col-6 col-md-2 form-group mb-2" xpath="1">
<input name="SMDetailsViewModel.SoRSummaryRowID" class="form-control rum-disabled" id="SRowID" type="hidden" value="3908" tabindex="-1">
<input name="SMDetailsViewModel.ID" **value**="20445" class="form-control rum-disabled " id="SID" type="text" tabindex="-1">
</div>
The 'value' needs to get printed and it is dynamic value.
I have tried with CSS, Xpath like below
WebElement SoR=driver.findElement(By.cssSelector("#SID")); With xpath as well
String SoRID=SoR.getText();
System.out.println("Here SOR ID" +SoRID);
tried with GetAttribute as well
Working with below
WebElement SoR=driver.findElement(By.cssSelector("#SID"));
String SoRID=SoR.getAttribute("value");
//String SoRID=SoR.getText();
System.out.println("Here SOR ID" +SoRID);
Problem: there are couple of radio button with same id and I need to perform click on these. The first radio button gets the click where the second one is getting StaleElementReferenceException.
Can Anybody Suggest me how it can be handled so that when I click the second radio button it does not throw StaleElementReferenceException
HTML:
<solvup-radio-type _ngcontent-c7="" _nghost-c10=""><div _ngcontent-c10="" class="validation-error ng-untouched ng-pristine ng-invalid">
<solvup-label _ngcontent-c10="" _nghost-c33=""><label _ngcontent-c33="" class="control-label">
Have you been able to resolve the issue based on this information? <!----><span _ngcontent-c33="" class="required-mark">*</span>
</label>
<solvup-tooltip _ngcontent-c33="" _nghost-c36=""><!---->
</solvup-tooltip>
</solvup-label>
<!----><div _ngcontent-c10="" class="radio">
<label _ngcontent-c10="">
<input _ngcontent-c10="" type="radio" id="ts_note_questions" class="ng-untouched ng-pristine ng-invalid">
Yes, issue is resolved - close case
</label>
</div><div _ngcontent-c10="" class="radio">
<label _ngcontent-c10="">
<input _ngcontent-c10="" type="radio" id="ts_note_questions" class="ng-untouched ng-pristine ng-invalid">
No - continue to next step
</label>
</div>
</div>
<solvup-hint-text _ngcontent-c10="" _nghost-c34=""><!----><p _ngcontent-c34="" class="help-block"></p>
</solvup-hint-text>
<solvup-validation-messages _ngcontent-c10="" _nghost-c35=""><!---->
<!----><div _ngcontent-c35="" class="form-group">
<small _ngcontent-c35="" class="err"><i _ngcontent-c35="" aria-hidden="true" class="fa fa-exclamation-triangle"></i> Please select an option</small>
</div>
</solvup-validation-messages>
</solvup-radio-type>
Selenium Code:
#Given("^User fills details in First of Five Troubleshooting page$")
public void user_fills_details_in_First_of_Five_Troubleshooting_page() throws Throwable {
Thread.sleep(2000);
List<WebElement> li = driver.findElements(By.className("radio"));
Actions ob = new Actions(driver);
ob.moveToElement(li.get(1));
ob.click(li.get(1));
Action action = ob.build();
action.perform();
}
Please suggest.
Looking at the dom-structure, you might be trying to click an element that might not be the right one. I would think
List<WebElement> li = driver.findElements(By.Id("ts_note_questions"));
Actions ob = new Actions(driver);
ob.moveToElement(li.get(1));
action.perform();
li.get(1).click();
would work, as you are trying to click on the input instead of the div.
I noticed you copied the first radio-button but it looks like you forgot to change the id of the second radio-button. Try to change the id of the second radio-button to a unique one.
I am new to selenium, tried different methods to click the Login button in a webpage, but ended up with "Unable to locate element: " error. Appreciate your help on how i can do it correctly.
<form class="LoginForm__Form-gmPGuK fIaXrM" autocomplete="off">
<div class="InputWrapper__Wrapper-dYpPUc btujOC">
<label class="Input__Container-evMrUq XWErm"><span class="Input__Label-dTgnUu ikGhjC">Username</span><input class="Input-eXLwAq eqVwiS" name="username" type="text" maxlength="20" autocomplete="off" value="" style="font-size: 1.6rem;"></label>
<p class="InputWrapper__ErrorMessage-bFHpkO jmYdPT">Invalid username</p>
</div>
<div class="Password__Wrap-kEDFHF gajvNg">
<div class="InputWrapper__Wrapper-dYpPUc btujOC"><label class="Input__Container-evMrUq ipuRfT"><span class="Input__Label-dTgnUu ikGhjC">Password</span><input class="Input-eXLwAq eqVwiS" name="password" autocapitalize="off" id="password" type="text" maxlength="20" autocomplete="off" value="" style="font-size: 1.6rem;"></label></div>
</div>
<div class="LoginForm__Agree-djIMue hEHJaH">By logging in, you agree to our <a class="LoginForm__Terms-diivNK iYiAkF" href="https://www.EEE.com/yyyyyyy/rr/terms-and-conditions.html" target="_blank">Terms & Conditions</a></div>
<button class="Button-hYXUXp bTvZVR" type="submit">LOG IN</button>
</form>
Try this code with WebdriverWait
WebElement username= driver.findElement(By.name("username"));
username.sendKeys("dsfs");
WebElement password= driver.findElement(By.name("password"));
password.sendKeys("fsdfdsfs");
WebElement LogInbtn= driver.findElement(By.xpath("//button[text()='LOG IN']"));
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(LogInbtn));
LogInbtn.click();
If it is in frame then first go to frame and then use above code
Hi I am using way2sms website and in send sms screen i am not able to enter the mobile number in mobile number field using selenium webdriver.
HTML Code: `
form id="smsFrm" name="smsFrm" method="post">
<input id="ssaction" type="hidden" name="ssaction" value="ss"/>
<input id="Token" type="hidden" name="Token" value="F448FDFD10E9288F9B4A204EF40EB29A.w803"/>
<div id="smilebox" style=" display:none;">
<div class="Sms fl">
<label>Mobile Number</label>
<div class="m91">
<span>+91</span>
<input id="mobile" type="text" onchange="javascript:dispLocMob(this);" onkeydown="javascript:dispLocMob(this);" onkeyup="javascript:dispLocMob(this);" value="" maxlength="10" placeholder="Mobile Number" name="mobile"/>
</div>`
Selenium Code :
`obj.findElement(By.xpath("//*[#id='sendSMS']/a")).click();
Thread.sleep(5000);
//obj.findElement(By.id("mobile")).sendKeys("8186867724");
obj.findElement(By.xpath("//*[#id='mobile']")).sendKeys("1234567890");`
Your element has an id, which is always the best way to address an HTML element using Selenium - very simple but still absolutely unique (bc otherwise it wouldn't be valid HTML). So try:
findElement(By.id("username"))
Full C# sample (should be similar in Java):
static void Main()
{
var driver = new ChromeDriver();
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(15));
driver.Navigate().GoToUrl("http://site23.way2sms.com/content/index.html");
IWebElement element = driver.FindElement(By.Id("username"));
element.SendKeys("000");
}
I switched to the frame and got it detected.
driver.switchTo().frame(driver.findElement(By.id("frame")));
driver.findElement(By.id("mobile")).sendKeys("123456");
I need to upload a file, but prior to that, I need to click on the Browse button. I have tried every possible way that I can think of, but no luck. I get an error "unable to locate element".
This is the page HTML
<div class="file_input_div">
<input type="button" value="Browse" class="file_input_button">
<input type="file" style="width:100px;" onchange="javascript: document.getElementById('fileName').value = this.value" value="" size="25" name="theFile">
My code:
WebDriverWait wait = new WebDriverWait(driver, 10);
//wait.until(ExpectedConditions.presenceOfElementLocated(By.name("theFile")));
wait.until(ExpectedConditions.visibilityOfElementLocated(By.name("theFile")));
driver.findElement(By.name("theFile")).click();