(ngx-datatable) Problems when doing filter (Removes the input value) - Angular - ngx-datatable

I hope they're very well, I need your help.
I have the following scenery.I write a value in input, when I filter the input value in row it deleted
Image 1:
Value in input
Image 2:
Value deleted in input
My html code:
html code
My filter code:
Filter code
I hope your answer.
Please.

Related

Xpath to select second text match instead of first one and selecting next element

I'm trying to select an element that has random generated class so my only way to select that element is using xpath.
The element I need to select is an input box with the previous label "City" but the problem is that it appears three times on the website and I want to select the second match on the website.
I have tried this, but it only selects the first one.
input = driver.find_element_by_xpath("//label[contains(text(),'City')]//following::input")
To select the second one I tried this but it doesn't work.
input = driver.find_element_by_xpath("//label[contains(text(),'City')]//following::input")[1]
Any help would be greatly appreciated.
You are missing an 's' in find_element_by_xpath. Try find_elements_by_xpath.
input = driver.find_elements_by_xpath("//label[contains(text(),'City')]//following::input")[1]
You can make sure there are expected 3 instances that match this xpath with some thing like:
input_all = driver.find_elements_by_xpath("//label[contains(text(),'City')]//following::input")
print("len(input_all):", len(input_all))
This would get only the second match:
input = driver.find_element_by_xpath("//label[contains(text(),'City')][2]/input")
if at all you are looking to get second matching element, you may try
WebElement input = driver.findElements(By.xpath("//label[contains(text(),'City')]//following::input")).get(1)
Strictly speaking, the following XPath fulfill your needs :
(//input[preceding::label[1][contains(.,"City")]])[2]
Select the 2nd input element on the page which respect the following condition : is preceded by a label element containing a specific text.

How to Select Choices input field having same class, type, Xpath everything is same

I have two input fields to enter choices which have same class, type. Id is different by it is dynamic and create on run time so i can't use id.I used indexing ,it's not working properly.
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][1]")).click();
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][1]")).sendKeys("Iphone 6");
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][2]")).click();
driver.findElement(By.xpath("//input[#type='text'][#placeholder='Provide a response entry that customers can select'][2]")).sendKeys("Iphone 7");
I used indexing in given image link.
click link to view code in organized way
Index 1 works in this case but unable to find index 2.
Given inspected html code is below of input field 1 and field 2
Field 1
Input field 1 image Xpath link
field 2
Input field 2 image link
If these two inputs are always in this sequence (so the first input is always first and second always second)
You can use:
driver.findElement(By.xpath("(//input[#type='text'][#placeholder='Provide a response entry that customers can select'])[1]")).click();
driver.findElement(By.xpath("(//input[#type='text'][#placeholder='Provide a response entry that customers can select'])[2]")).click();
At the same time I have corrected the syntax in indexing
Building on #Anand 's answer, you can simplify a little:
WebElement button1 = driver.findElement(By.xpath("(//input[#type='text' and #placeholder='Provide a response entry that customers can select'])[1]"));
WebElement button2 = driver.findElement(By.xpath("(//input[#type='text' and #placeholder='Provide a response entry that customers can select'])[2]"));
I think it's a little easier to read using and instead of stacking brackets.
I use it similarly for widgets:
WebElement header = driver.findElement(By.xpath("//div[contains(#class,'panel')]/div[contains(#class,'panel-heading') and text()[contains(.,'News Feed')]]"));

I am unable to enter data using send keys

I am unable to enter data in a required field of format __-_______ (it is a 9 digit number) and not getting any errors on console.Cursor entered into the field and moved from starting to end of the field but data not entered.
I have tried below code formats...
driver.findElement(By.id("vendoridentificationnumber")).sendKeys("12-3456789");
--- not working.
driver.findElement(By.id("vendoridentificationnumber")).sendKeys("123456789");
--- not working.
driver.findElement(By.id("vendoridentificationnumber")).sendKeys(s.getCell(3,1).getContents());
--- not working.
Please help me out with this.
Do one thing, without inspecting the element where you want to insert the number simply you can inspect just before element and using Keys class you can jump to your text field and enter your data. Below is a sample line of code
d.findElement(By.xpath("")).sendKeys(Keys.TAB,"enter your value");
Hope it'll work.
Use javascript to enter the value in the textbox.
Eg :
$('#textboxid').val('test')

WebDriver find by xpath where //input[#value='empty']

I need to find an input element with an 'empty' value by xpath.
Something like //input[#value='empty']. I don't mean the word 'empty', but the value is empty or blank.
What Xpath will return such element?
Thanks
Since the link I posted in the comment is a potential solution
So, I thought to post it as an answer:
How do I select an empty element in XPath?
Edit:
Based on advice from the comment to duplicate the essential parts of the linked answer (incase the link becomes obsolete), please find it below:
You could use XPath's not() function.
a[#href='#'][#class='button save-as'][#title='SaveAs...'][not(text())]
Next time post html snippet so that people will understand parent and target element
the below code will work, but if more input fields with null values are there then more than one result will be returned. [i am sure below xpath will return many results]
so please include parent node in below xpath
//input['not(text())']
the input belongs to text area, submit button, radio button , check box ....
again, post the HTML snippet next time. when you ask question related to xpath.

How to get text from input tag?

I've a case where I've to get the text from input tag which is something like -
<input id="AB_WIN_1" class="text real" type="text" ds="0" style="top:0px; left:167px; width:140px; height:21px;"/>
And the text in that input tag is some text say Hello
But when I use getText, it returns nothing.
Is there anyway I can get text from input tag?
you can use any of the below:
1. element.getAttribute("value")
2. element.getAttribute("innerHTML")
3. element.getAttribute("innerText")
4. element.getText()
5. ((JavascriptExecutor)driver)execute.script("return arguments[0].value",element)
Let me know if this does not helps.
use element.getAttribute("value"). getText can not extract input value.