In this website I have to get the tooltip text of this element:
If I write xpath //html/body/div[2]/table/tbody/tr[2]/td[1] I get the KWPH-48 text. Is there a way to get this tooltip text Create a new OneDrive folder ?
try following using getAttribute() function:
String toolTip = driver.findElement(By.xpath("/html/body/div[2]/table/tbody/tr[2]/td[1]")).getAttribute("data-original-title");
I figured out finally:
Command: storeAttribute
Target: //html/body/div[2]/table/tbody/tr[2]/td[1]/span#data-original-title
Value: variableName
Related
I'm trying to automate Filter By Brand scenario in BigBasket and now stuck up in a situation where my code could not print the brand names that are hidden inside a scroll bar.
Steps to follow
Go to www.bigbasket.com
Click Skip & Explore button
Search Apple and view the list of brands on the left side
#FindAll({#FindBy(xpath="//*#id='filter_brands_list']/div/div1/li/label")})
List chkBrands;
The above lines of code identifies all the brand names but when I print them using the below code I can see only the brand names that are visible
for(WebElement eachElement:chkBrands){
System.out.println("No. of brands is "+chkBrands.size());
System.out.println(eachElement.getText());
}
Could you please let me know the solution? I apologize that I could not think of a solution as I'm an amateur in Selenium.
WebElement.getText() will return the text of the element only if it is displayed on the screen.
Meaning if the isDisplayed method returns false then getText()method will return empty.
Explanation with Examples Here
As defined in WebDriver spec, Selenium WebDriver will only interact
with visible elements, therefore the text of an invisible element will
always be returned as an empty string.
However, in some cases, one may find it useful to get the hidden text,
which can be retrieved from element's textContent, innerText or
innerHTML attribute, by calling element.attribute('attributeName') or
injecting JavaScript like return arguments[0].attributeName.
So you can get the text by textContent attribute
eachElement.getAttribute("textContent")
Try this one:
JavascriptExecutor je = (JavascriptExecutor)driver;
WebElement element = driver.findElement(By.xpath("Your_xpath"));
String text_value = ((JavascriptExecutor) driver).executeScript("return arguments[0].innerHTML;",element);
I have an autocomplete textview and I am setting an Adapter view on it to show the list of suggestions. While testing on espresso, I want to select an item position from list of suggestions but, it does not identify the auto complete text view adapter on espresso.
I tried this answer from Stack overflow:
DropDown value selection using espresso android with dynamic element id's
But, this did not work for me. Any help on this would be great.
Thanks.
or you can try instead onData. Because onData not working for me
onView(withText("Your field name"))
.inRoot(withDecorView(not(is(getActivity().getWindow().getDecorView()))))
.perform(click());
I run into the same problem and this is how i did it:
onView(withId(R.id.sp_country/*auto complete textview*/)).perform(click());
onData(allOf(is(instanceOf(String.class)), is(COUNTRY/*selected value autocomplete collection*/)))
.inRoot(RootMatchers.withDecorView(not(is(activityActivityTestRule
.getActivity().getWindow().getDecorView()))))
.perform(click());
I'm trying to insert a link into an instance of CKEditor using the following line: -
CKEDITOR.instances.CKInstance.insertHtml('My Text');
All that happens though is that 'MyText' is inserted without the link. Anyone know how to insert the link properly?
PS. I know that CKEditor comes with a plugin to insert links but I'm doing my own one
Thanks
Shazoo
I guess that you're using CKEditor 4.1 or newer. And since you don't use the official link plugin, your editor discards all <a> tags. You need to properly configure Allowed Content Filter so your editor accepts <a> tags back again.
You can do it when defining your command, like this:
// Assuming you want a dialog-driven command...
editor.addCommand( 'yourCommand', new CKEDITOR.dialogCommand( 'link', {
allowedContent: 'a[!href]', // Allow <a> in the editor with mandatory href attr.
requiredContent: 'a[href]' // This command requires <a> with href to be enabled.
} ) );
Or in editor's config with config.extraAllowedContent = 'a[!href]'. This is not recommended though as you develop a plugin (right?), which should bring a custom command.
I've been working on a custom field, which contains a list.
I have to be able to edit the selected item on the list in a richtext editor. (this is the only missing part).
I've read the topic on opening from c# code Opening Rich Text Editor in custom field of Sitecore Content Editor .
This works nice for the "add" button, since i have to open the RTE empty(with default text...), but not for the Edit button.
My aproaches are:
Somehow in the Edit button's message field list:edit(id=$Target) pass the selected index (like list:edit(id=$Target,index=$SelectedIndex), but i don't know how to populate $SelectedIndex
Somehow in the overridden HandleMessage method get the list's selected index. I'm able to get the selected value Sitecore.Context.ClientPage.ClientRequest.Form[ID of list], but thats alone not much of a help, since i won't be able to decide which one to edit if two listitem equals.
Do the richtext editor opening and handling fully in javascript. As i saw at some script in content editor, i tried to do that, but i can't understand it clearly:
richtext editor url:
var page = "/sitecore/shell/Controls/Rich Text Editor/EditorPage.aspx";
some params :
var params = "?da=core&id&ed=" + id + "&vs=1&la=en&fld=" + id + "&so&di=0&hdl=H14074466&us=sitecore%5cadmin&mo";
and the part where i'm not sure:
var result = scForm.browser.showModalDialog(page + params, new Array(window), "dialogHeight:650px; dialogWidth:900px;");
This way the RTE opens as expected (i guess i could get the selected index from javascript and pass it as a parameter later). However when i click ok, i get exception from EditorPage.js saveRichText function: Cannot read property 'ownerDocument' of null. Am i missing some parameter?
Either of the three aproaches is fine for me(also i'm open for new better ones) as soon as i'm able to do it.
Thanks in advance!
Tamas
I was able to enter some javascript into the message:
list:Edit(id=$Target,index='+document.getElementById(ID of the select using $Target ).selectedIndex+')
this way i got the index in HandleMessage.
I'm waiting for better solutions now.
The website I am testing upon clicking a link provides a JavaScript prompt box containing a url within the text input field.
Is there anyway of copying just the link stored within the text field and storing it within a variable?
example of the JavaScript prompt:
window.prompt("here is the link", "www.google.com");
What I've tried:
browser.alert.text
returns the result of - "here is the link"
edit:
Image of the event
Thanks.
As far as I can see Alert class returns only text: http://rubydoc.info/gems/watir-webdriver/Watir/Alert
Yes, just do
var ret = window.prompt("here is the link", "www.google.com");