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
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);
How to select C++ value if any radio button not selected
<form name="testform" action="" method="POST">
<div align="center">
<br>
<input type="checkbox" name="option-1" value="Java">Java
<input type="checkbox" name="option-2" value="C++">C++
<input type="checkbox" name="option-3" value="Python">Python
</br>
</div>
We can induce a simple check on the WebElement to check if it is selected or not and if not selected click on it to select as follows:
WebElement element= driver.findElement(By.xpath("//input[#name='option-2']"));
if(!element.isSelected())
{
element.click();
}
You can use this :-
webElement element= driver.findElement(By.xpath("//input[#name='option-2']"));
element.getAttribute("value"))
or
element.getText();
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.
I am writing selenium script for Autotrader.com signup page. I am not able to click on 'I Agree' Check box. This is what I have written:
WebElement cboxlink = driver.findElement(By.id("j_id_29-j_id_2h-"
+ "myatcRegisterForm-j_id_3n-acceptTerms"));
cboxlink.click();
The HTML is:
<div id="j_id_3n" class="atcui atcui-form-row atcui-clearfix atcui-small terms" style="">
<input id="j_id_29-j_id_2h-myatcRegisterForm-j_id_3n-acceptTerms" class="checkbox" type="checkbox" value="true" name="j_id_29-j_id_2h-myatcRegisterForm-j_id_3n-acceptTerms">
<label for="j_id_29-j_id_2h-myatcRegisterForm-j_id_3n-acceptTerms">
I accept terms of the
<a target="_blank" href="/privacy.jsp">Privacy Statement</a>
and <a target="_blank" href="/legal/visitor-agreement.xhtml">Visitor Agreement</a>.
</label>
Can any one please help me out how to select a radio button if it is inside a fieldset??
I can access individual radio button using foreach but when i try to select it or click it its giving some Ajax error.
HTML code is given below
I have tried to select it with radio button's label as well as given in above comment but not able to select it.
<fieldset id="edit-cvs-options" class="form-wrapper">
<legend>
<div class="fieldset-wrapper">
<div class="ios-content" style="display: none;">test</div>
<div class="form-item form-type-radio form-item-use-stored">
<label for="edit-use-stored">
<span>test</span>
<input id="edit-use-stored" class="form-radio" type="radio" name="use_stored" checked="TRUE" value="on" display-title-fix="1"/>
</label>
</div>
<fieldset id="edit-cvs-1" class="form-wrapper" style="display: inline-block;">
<div>
<div class="form-item form-type-radio form-item-use-uploaded">
<label for="edit-use-uploaded">
<span>test</span>
<input id="edit-use-uploaded" class="form-radio" type="radio" name="use_uploaded" display-title-fix="1" value="off"/>
</label>
</div>
</div>
</fieldset>
This is my Behat step definition:
$session = $this->getSession(); // get the mink session
$escapedValue = $session->getSelectorsHandler()->xpathLiteral('use_uploaded');
$radioButton = $session->getPage()->find('named', array('radio', $escapedValue));
$radioButton ->click();