select the next button- xpath-selenium - selenium

I am exactly in the line where there is the text ='Ver Informe'.
I want to go to the button that is next to that line.
Because only work when I make the click there.
Could you help me go there?
I tried: /button1 -- and doesn't work.

I need to see more of the surrounding html but if I understand your question correctly you want the button that contains the element with the text 'Ver informe'.
Try this:
//div[4]//article[1]//descendant::button[#type='button' and ./*[contains(text(),'Ver informe')]]

basically the span is wrapped in the button tag. So you can use the below xpath.
//span[normalize-space(.)='Ver informe']/parent::button

Related

Selecting the correct "Add" button

I have a field that has a "+" Add button in case you want to add more lines. I want to add 2-3 lines with it, then to click on the "+" button from a newly created line to create 2-3 more. The problem is that all buttons are declared the same:
<button class="ng-scope" ng-if="formData.order_request_status == STATUSES['OPEN']" ng-click="addImportMaterial()" style="margin-left: 3px;" type="button">+</button>
I have written the following xpath:
//button[#ng-click='addImportMaterial()']
but this selects all plus buttons and I want only the third one to be pressed. Any ideas? Thanks!
You should try using xpath with index then as below :-
I want only the third one to be pressed
(//button[#ng-click='addImportMaterial()'])[3]
So, (Assuming your using java) use above xpath to locate third button and click as :-
driver.findElement(By.xpath("(//button[#ng-click='addImportMaterial()'])[3]")).click()
Since you will be getting a List of buttons, to press the third one you just have to do buttons.get(2).click();

selenium ide : click button with class on specific row in table

I have an html table wich contain multiple lines.
At the end of each line, the last row contain multiple button. I would like to click on the remove button of the first line.
I tried this Xpath code but the element in not located :
There is a mistake somewhere in my xpath query :
//table[#id='tableTest']/tbody/tr[8]/td[8]/a[#class="remove"]
Your query looks pretty OK, but there is no HTML code so we can just guess what happen. What about the number 8?
Try to use XPath axes. For example locator could look like this:
//table[#id='tableTest']/tbody/tr[1]/descendant::a[#class="remove"]
This should find the remove button in the 1st row whenewer it is.
Click the button of the first line... which I think you mean first row?
//table[#id='tableTest']/tbody/tr//a[#class="remove"]
That SHOULD find the first tr (row) of your table and select the href with the class remove. But it's not going to ensure it's the last cell, which if that's vital you'll need to use something like //table[#id='tableTest']/tbody/tr/td[last()]/a[#class="remove"]
Also, if you attach the html snippet this becomes much easier for many of us to answer.

Selenium, using xpath to click a button with a similar content

I want to click a button that contains "Add" as text.
ie:
driver.find_element_by_xpath("(//a[contains(text(),'Add')])").click()
however it's not practical to do this:
driver.find_element_by_xpath("(//a[contains(text(),'Add')])[1]").click()
It would be fine, except the page has a button with text "Add User", and it clicks that instead. Is there a way to only click it if it is EXACTLY "Add" and not just contains "Add"?
You can also try :
driver.find_element_by_link_text("Add").click()
link text will match links who's text equals Add and it doesn't match text which contains Add as part of it.
This should work for you:
driver.find_element_by_xpath("//a[text()='Add']").click()
You should change your xpath to require an exact match instead of a partial match.
driver.find_element_by_xpath("//a[text()='Add']").click()
Using text()= requires the text on the button to be equal to 'Add' and will not find other buttons that happen to contain the text 'Add'

How can I achieve a list item with an X button at the end for removing it? (see screenshots)

I'm using a QListWidget along with QListWidgetItem.
What I want to do is put a small "X" button at the end of the list item for removing it. Just like the one in QtCreator.
A link to example code is fine. I just need a hint on how to achieve this.

Text input issues with Visual Basic

Ok, I'm writing a program in vb. It's simply a text editor. However i've run into a little snag. My program has options to click a button and text is inserted into the text box. I am using this line:
textbox.AppendText (sometext)
Now this code works great if i want the text to be added at the bottom of the page. So here's my question, is there any way to modify or maybe replace this code so that the text is inserted were the cursor is?
Try setting .SelectedText property or using .Paste(String).
Not through the textbox control itself, as far as I know. You will need to use the SelectionStart property to manually insert the text.
textBox1.Text = textBox1.Text.Substring(0, textBox1.SelectionStart) & "INSERTEDTEXT" & textBox1.Text.Substring(textBox1.SelectionStart)
This is assuming you want to insert the text and not just replace it.