Code
Hey guys,
I am new to Cypress and have a hard time finding solution for this problem. The #label element which is a div has a text value and I dont know how to print it to a web console. Appreciate all help
You can do like this:
cy.get('selector')
.find('selector')
.find('selector')
.find('selector')
.eq(0)
.find('selector')
.eq(1)
.find('#label')
.invoke('text')
.then((text) => {
cy.log(text) //logs the text
})
Related
I'm trying to insert a button in CKEditor5. Most of it is working OK but when I click on the right side of an inserted element it results in an extra empty element.
Here is the YouTube video of the behavior: https://www.youtube.com/watch?v=XXLyJcJJk00
...And some of the code to insert the View Fragment:
editor.model.change(writer => {
const viewFragment = editor.data.processor.toView('' + value.text + '');
const modelFragment = editor.data.toModel(viewFragment);
writer.model.insertContent(modelFragment);
writer.setSelection( editor.model.document.getRoot(), 'end' );
});
You can see there are ⁠ ASCII characters in there.
I've been stuck on this for several days now so any help would be much appreciated.
I am working with CKEditor 5 (Baloon Editor) and trying get selected text.
How can I do it?
I tried below code and got NULL:
editor.model.change( writer => {
var selection = editor.model.document.selection;
console.log(selection.getSelectedElement());
} );
Thanks for help.
I guess, selection.getSelectedElement() returns null for text elements. It returns an element object when figure objects selected. You can use
selection.getFirstPosition().parent
or
Array.from(selection.getSelectedBlocks())
I want to retrieve hidden text when the visibiility attribute is hidden:
<div id = "tt52433002" class="yui-module yui-overlay yui-tt yui-overlay-hidden" style="z-index: 2; visibility: hidden;">
<div class="bd">Associated with the domain : testci20160503105556.com</div>
</div>
I tried:
browser.hidden(:class, 'bd').text
and
browser.hidden(:class, 'bd').value
But I get this error:
"unable to locate element, using {:class=>"bd", :tag_name=>"input", :type=>"hidden"}"
Watir is designed to act like a user. So if a user can not see the text in an element, then Watir will not return the text of the element.
Also, the element you are looking for is a div not a hidden.
If you need the text you can do:
browser.div(class: 'bd').inner_html
which makes a JavaScript call to provide the result.
This works:
browser.div.attribute_value('id') => tt52433002
as does this:
browser.div(class: 'bd').inner_html[/testci\d{14}/] => testci20160503105556
First things first. The error says that Watir cannot find an element using the criteria you specified. That means either that no such thing exists anywhere in the DOM, or that it might be inside a frame.
Since the element you want is a div, then you should be using the .div method to access it
browser.div(:class => 'bd') #finds first matching div
A potential second problem could occur if that classname is not very unique. Unless you specify an additional parameter, such as index, or perhaps a portion of the text contained by the div, you may not find the div you are looking for. A fast debugging trick (I like to do it from IRB) is to get a collection of matching divs and check the size
div_count = browser.divs(:class => 'bd').size
puts "there are #{divcount} divs of class bd in the dom"
If the count is anything more than 1, then you likely need to change how you are selecting it to ensure you get the right one. for example
browser.div(:class => 'bd', :text => /Associated with the domain/)
If the count is zero, then check for frames
frame_count = browser.frames.size
iframe_count = browser.iframes.size
If there are frames you will have to tell watir to look inside the frame for the div, if more than one frame then be sure you specify the right one
browser.frame.div(:class => 'bd') #looks for div inside first frame
Once you are sure you have the right div, then you ought to be able to use a method like .text or as in another answer .inner_html to get the contents of the div.
I tried xpath and id
getting `until': timed out after 10 seconds (no such element (Selenium::WebDriver::Error::TimeOutError)
I am using rubymine editor.
wait = Selenium::WebDriver::Wait.new(:timeout => 10)
wait.until { #driver.find_element(:xpath => "//*[#id='j_id0:pb:j_id35']") }
#driver.find_element(:xpath => "//*[#id='j_id0:pb:j_id35']").send_keys "test send sms"
Text area element is placed on bottom of the page.Do I need to scroll down the page and click and sendkeys in the text area.
in the below code I am trying to find nearest element to the text box and do scroll down later click on text area and sendkeys.But even it's not working..
#wait = Selenium::WebDriver::Wait.new(:timeout => 10)
#wait.until { #driver.find_element(:name => "j_id0:pb:j_id33") }
#scroll = #driver.find_element(:name => "j_id0:pb:j_id33")
#scroll.location_once_scrolled_into_view
Please help on this..
Thanks!!
I don't have idea on rudy but can help you logically..
1) first scroll the page from your code to the text area.
2) select the text area by id, xpath or etc. driver.findelement(by.id(...)).sendkey(..........);
Thanks Shukla!#sourabh shukla
Mine inside has frame so I need to switch to frame that is why I am not able ciclk that element!!
#driver.switch_to.frame("06618000000Crrp"#this is id);
Then my element found and entered text!!
Is there a way to verify is element hidden or not - using watin.
I don't want to use Jquery.
Thanks
I managed to work around this by running some jQuery in the browser that reported whether the element was hidden or not:
var jsCommand = String.Format("$('#{0}').is(':visible');", fieldId);
var isVisible = ie.Eval(jsCommand) == "true";
In my experience, there is no concrete way to tell if an individual element is hidden or not in watin.
However, you can recursively check up through the parent tree to see if they contain "display: none" or "visibility: hidden"
This blog gives more detail:
http://blog.coditate.com/2009/07/determining-html-element-visibility.html
You may want to check what method your developers use to hide elements to know if this solution is useful for you.
Not sure if this is any help, but I recently had to use a hidden text field...
public TextField HiddenTitleTextField
{
get
{
return this.Document.TextField(tf => tf.Name == "title" &&
tf.GetAttributeValue("type") == "hidden");
}
}
HTH!