I'm trying to insert text into a textarea with a wysiwyg editor (summernote) from a form, i'm using behat featurecontext file for this. The textarea doesn't have a id tag so i need to select the class using javascript code:
document.getElementsByClassName('note-editing-area').item(0).innerText="something"
But when i do this, also the innerhtml is overwritten with the text from innerText.
Any suggestions?
Best way is to set an id or class and select that. If you do not use that it is way more difficult to maintain. You could add this through twig:
{{ form_widget(form.task, {'attr': {'class': 'task_field'}}) }}
Related
In a selenium script Sorting a dropdown using
new Select(driver.findElement(By.cssSelector("select[title=\"Sort By\"]"))).selectByVisibleText("Name");
Can anybody please explain me this part cssSelector("select[title=\"Sort By\"]" of above statement.
Thanks!
cssSelector("select[title=\"Sort By\"]")
this is one of the technique to locate web element/elements.
You must have heard about xpath, which is one of the way to locate element/elements in a web page.
Further more , select is tag in HTML. title is attribute and Sort By is value of attribute.
Just like this :
HTML :
<select id="sel" class="drop-down" title="Sort By">
<options>..</options>
<options>..</options>
<options>..</options>
</select>
Now If you have to write cssSelector , you can write like this :
tagname[attribute="attribute value"]
select[id="sel"]
or
select[class="drop-dwon"]
or
select[title="Sort By"]
Hope this will be helpful !
new Select(driver.findElement(By.cssSelector("select[title=\"Sort By\"]"))).selectByVisibleText("Name");
You are selecting by CSS selector https://www.w3schools.com/cssref/css_selectors.asp. The alternative is XPath which is more powerful but harder to learn.
What this part By.cssSelector("select[title=\"Sort By\"]") does is select all select elements that have title attributes set equal to "Sort By". Although by prefixing driver.findElement( you are requesting just one element, the first. At least you would be if it was python, Java might differ but was not in your question nor tags.
I want to select a checkbox with the HTML code shown below using the attribute bayid:
<input type="checkbox" devid="bay" bayid="10" checked="">
I could get the XPath information - "//*[#id="svbSelectEnc1"]/table/tbody/tr[7]/td[3]/input", but I want to use the bayid for selecting as there are lot of checkboxes in the form of a table and only specific checkboxes have to be selected that are read from the config file.
You can achieve it by using CSS Selector or XPath as shown below.
By CSS Selector
driver.findElement(By.cssSelector("input[bayid='10']")).click();
By XPath
//input[#bayid='10']
Also I would suggest you to go through basic tutorial on how to find WebElement using CSS Selector and XPath
try the following XPath:
//input[#bayid='10']
CSS selector way to do this:
driver.findElement(By.cssSelector("yourTagName[attribute='attributeValue']")).click();
For your specific case:
driver.findElement(By.cssSelector("input[bayid='10']")).click();
I'm currently creating an automation test for a website and I want to check if a text(s) is in the page. I could use the keyword 'Page should contain' to check; however, I want it to be a little more specific on having it check specifically where the text exist in the page. Is there a way I can have it check if a specific div contains the text?
You can easily do this with a built-in Selenium2Library tags.
For a partial match use this:
Element Should Contain locator expected_text
For an exact match use this:
Element Text Should Be locator expected_text
If your HTML code is something like:
Your div tag and need to find FindMe
<div class="gwt-Label">This FindMe DIV</div>
Then you can find "FindMe" text like:
//div[#class='gwt-Label'][contains(string(),'FindMe')]
Say i have a text area:`
<body contenteditable="true" class="html-editor portlet portlet-blogs cke_show_borders" spellcheck="false"><p><br type="_moz"></p></body>`
As you see there is no id so i want to idenify it using class attribute.
Try this
css=tag.class
tag=HTML tage of the element
class=class of the element
type this in target
css=body.html-editor portlet portlet-blogs cke_show_borders
Use this :
//body[#class='html-editor portlet portlet-blogs cke_show_borders']
You have to find Xpath of the text field, use Xpath to identify the text field and selenium ide you have to write following command
type|Xpath of text field | your content
you can install firepath plugin in FF browser and take xpath of text box through firebug,
EG: //*[#id='search']/div/input
while writing some acceptance tests for my webapp (playframework based),I got confused by the usage of some selenium commands.
In my html page,I have a submit button like this
<input type="submit" id="removecartitem" value="remove"/>
to locate this,I used
assertElementPresent(id='removecartitem')
however,this fails,
assertElementPresent id='removecartitem' false
The selenium documentation says
id=id: Select the element with the specified #id attribute.
but,if i simply put
assertElementPresent('removecartitem')
Then,the test is executed correctly.This is the source for confusion, since the default way is to select the element whose name attribute is 'removecartitem' ,and I haven't mentioned any name attribute in my html
Any idea why this happens?
It looks like you need to remove the single quotes according to the documentation you provided...e.g:
assertElementPresent(id=removecartitem)