I'm trying to create some e-mails via automation but I'm stuck at;
https://app.tutanota.de/#register
<div class="record">
<div class="recordName"></div>
<div class="formAction">
<button class="single fontImage confirm disabled" type="submit" data-bind="css: { disabled: !isCreateAccountPossible() }, lang: 'createAccount_action'">Hesap oluştur</button>
<button class="single" data-bind="fastClick: login, lang: 'backTologin_action'">Giriş'e dön</button>
<label class="recordStatus invalid" data-bind="lang: getCreateAccountErrorMessage()">Lütfen bir şifre giriniz.</label>
</div>
</div>
But I cannot even locate or click this button
<button class="single fontImage confirm disabled" type="submit" data-bind="css: { disabled: !isCreateAccountPossible() }, lang: 'createAccount_action'">Hesap oluştur</button>
I tried with xpath and classname like;
driver.findElement(By.xpath("//button[#type='button' and #class='single fontImage confirm']")).click();
driver.findElement(By.classname("single fontImage confirm"));
and I tried like ;
driver.findElement(By.cssSelector("...(divs and classes until I reach button classname like #somediv .someclass #anotherdiv .anotherclass .single fontImage confirm)"));
Also, this button class is changing when you put informations like mail and password but untill that point its class name is single fontImage confirm disabled after putting informations its class becomes single fontImage confirm
I know this is really basic question but I tried lots of things to get it work but no luck. Any help is appreciated. Thanks !
All your locators are incorrect. The first by.xpath issues are at button type and class. The button type is 'submit' and class should use contains instead of equal. The second by.classname is incorrect because 'disabled' is missing. I don't understand the third cssSelector.
You can use cssSelector:
By.cssSelector("div.formAction > button[class*='single fontImage']");
or XPath:
By.xpath("//div[#class='formAction']/button[contains(#class,'single fontImage')]");
The most convenient way of selecting element by CSS classes is using CSS selector :
div.formAction > button.single.fontImage.confirm
The above selector will find div element with class formAction, and then return child element button containing all but not limited to the following classes: single, fontImage, and confirm.
Related
I'd like to select some schemas on the screen for testing. But there are 8 different types schemas. And I couldn't select any schema without click on the schema's image. The element is displayed like this;
I created web element list and filtered it on value that i wanted to select schema name with java 8 stream than i can replace filtered element with (up div[class=' up template-list-board row']>div>P to div[class='template-list-board row']>div>a) , but it was not a good idea, i've experienced.
So , is there any way to click that "a" tag?
The html is displayed like this;
<div class="template-list-board row">
<div class="template-item-list">
<a class="item-image-click" ....> </a>
<p class="item-name">Meeting Agenda</p>
</div>
<div class="template-item-list">
...
</div>
I am not sure if I am understanding you correctly, but my solution would be something like this (with XPATH not css):
1) create a string for the locator:
String locator = "//div[class='template-list-board row']//p[text()='" + hereYourNameVariableAsString + "']/preceding-sibling::a";
2) Then create your element :
WebElement element = driver.findELement(by.xpath(locator));
Here the important thing is that you locator is dynamic you will have to provide you menu name or whatever that name represent such as "Meeting Agenda". Then it will find that menu and the previous sbling a for clicking. I hope I understand the problem correctly and this helps.
Basically there are 3 types of Save button in a page. Now, the button which I'm trying to click on is a type="button" and remaining types of save are not defined as type="button".For all three save buttons LinkText is defined as Save. So, is there any way to click on type="button" by linkText.
HTML:
<button class="btn btn-md bgm-blue m-r-10 waves-effect" ng-click="updateUser()" type="button">Save</button>
Code which I tried:
List<WebElement> list = Util.getWebDriver().findElements(By.xpath("//*[text()='Save']"));
System.out.println("SaveButton"+list.size()); ///Returning 3 save button in a page
list.get(3).click();
Now, suppose in one page there are 4 save buttons and in another page there are 3 save buttons. So, it is not possible to make a method because each time index will differ.
If there is any way to find xpath by type="button". Will be easy for me to make a method and call it each time I want to click on"Save".
Please let me know in case of clarification.
is there any way to click on type="button" by linkText
Actually By.linkText() is use to locates <a> elements only that contain the given link text while you're trying to locate <button> element. So you can not locate desire element using By.linkText().
button which I'm trying to click on is a type="button" and remaining types of save are not defined as type="button"
As you are saying only desire button contains attribute type="button", So it is very easy to find that element using other locator as below :-
By.cssSelector() :
button[type='button']
button[type='button'][ng-click='updateUser()']
button.btn.btn-md.bgm-blue.waves-effect[type='button'][ng-click='updateUser()']
By.xpath() :
//button[text()='Save' and #type='button']
//button[.='Save' and #type='button']
//button[text()='Save' and #type='button' and #ng-click='updateUser()']
//button[.='Save' and #type='button' and #ng-click='updateUser()']
As the Save button contains class attribute you can construct an xpath as follows:
findElements(By.xpath("//button[#class='btn btn-md bgm-blue m-r-10 waves-effect'][contains(text(),'Save')]"));
How to handle this kind of pop-up. My goal is to get the message when Submit button clicked then validate it againts my own text (maybe using assert). I've tried to locate the element using firepath (xpath) but when i click locate Element button on firebug, the pop-up disappear.
Here is the screenshot of the pop-up.
popUp
Here is the code :
<p class="errors"></p>
<input id="email" class="form-control" type="email" value="" name="email" required="" oninput="setCustomValidity('')" oninvalid="this.setCustomValidity('Email Cannot Be Empty')" placeholder="Email *" data-placeholder="X" data-format="">
Thank you in advance.
From the scrrenshot it looks like a tooltip. Something like when we mouse over Google title in https://www.google.co.in/.
To verify tooltip we can get the attribute 'title' and verify.
Example : in https://www.google.co.in/. tooltip is placed in title attribute as below.
title="Google"
<div id="hplogo" style="background-size:272px 92px;height:92px;width:272px" title="Google" onload="window.lol&&lol()" align="left">
For your scenario, the displayed tip message is available in 'oninvalid' attribute as below. So get this attribute value and validate it.
oninvalid="this.setCustomValidity('Email Cannot Be Empty')"
If the element is not inside a iframe, then you can directly try as follows:
String emailId = driver.findElement(By.id("email")).getText()
// write string equals login here comparing emailId that is captured and the one you want to compare to.
if not, first find the iframeand switch to it and then use above code to find the element. More detailed answer related to switching b/w frame is here
Finding the elements in the Pop-up:
Instead of clicking on the Locate Element button (of Firebug) first, Right click on the element you want to find in the Pop-up, and select Inspect with Firebug, which gives the corresponding HTML code for the element.
This is a bit late in the game but the way you get the custom validity message and not the generic one you have to call the reportValidity() event within JavaScript in Selenium. You'll see a driver.executeScript() method and this is where you must call the reportValidity event on the element being validated. This is how I did it:
wait.Until(SeleniumExtras.WaitHelpers.ExpectedConditions
.ElementToBeClickable(By.CssSelector("input#NewPassword.form-control")));
IWebElement input = driver.FindElement(By.CssSelector("input#NewPassword.form-control"));
input.SendKeys(string.Empty);
IWebElement form = driver.FindElement(By.TagName("form"));
form.Submit();
driver.ExecuteScript("document.getElementById('NewPassword').reportValidity();");
Assert.AreEqual("New password required", input.GetAttribute("validationMessage"));
I am trying to click on some button (which becomes enabled after all of the fields are fill in):
<div class="savCancelContainer">
<input type="button"
value="Save"
translatekey="ACTVITY_DETAILS_SAVE_BUTTON"
class="translate" id="submitActivityDetails"
style="background-color: rgb(0, 125, 195);">
The programmers of the web-page have changed it for some reason, and now my code is no longer working correctly (the button doesn't get clicked on):
driver.findElement(By.id("submitActivityDetails")).click();
I also tried finding it by xpath, with no success.
Is there any way to click the button using the Id and Value attributes together?
Any other ideas?
Similar pages and dialogs are still working fine...
You need to create a xpath which will contain both the attribute:
//input[#id='submitActivityDetails'][#value='Save']
And Click event can be triggered in the following way:
driver.findElement(By.xpath("//input[#id='submitActivityDetails'][#value='Save']")).click();
Lemme know if it helps!
Additionally you can use css seelctor to perform that action too.
[id='submitActivityDetails'][value='Save']
I have a number of buttons like this:
<button data-pjax class="btn btn-inverse" type="button" onclick="location.href='http://mybuttonurl.com'">my button</button>
And a number of urls like this:
<a data-pjax href="http://mylinkurl.com">My url</a>
I want PJAX to work on both the buttons and the links. This code works for the links:
$(document).pjax('[data-pjax] a, a[data-pjax]', '#pjax-content');
So does this:
$(document).pjax('a', '#pjax-content');
I can't seem to get it working for buttons and links. Even this won't work for buttons alone:
$(document).pjax('button', '#pjax-content');
How can I get this to work?
Note: when I say "won't work" it means the page does a full refresh rather than just load the HTML content into #pjax-content.
As I am using Twitter Bootstrap I ended up replacing the button with a link:
<a data-pjax class="btn btn-inverse" type="button" href='http://mybuttonurl.com'>my button</a>
I believe this is a better way to do what I was trying to do + PJAX works cross browser this way