How to locate second image which contain specific text - java

The website has standard image which i can use to identify the xpath.
but i want to click on the third image which contains specific text only.
the picture is beside the image, it that fine to have img and text in one command line?
Original working code:
driver.findElement(By.xpath("(//img[#class='s-image'])[2]")).click();
Try to insert the contains command but it does not work:
driver.findElement(By.xpath("(//img[#class='s-image'])[2] and contains(text(),'Apple MacBook Pro')")).click();

You have tried wrong option that is not text that is alt property to get into xpath.Try now.
driver.find_element_by_xpath("(//img[#class='s-image'][contains(#alt,'Apple MacBook Pro')])[2]").click()
OR
driver.find_element_by_xpath("(//img[#class='s-image'][starts-with(#alt,'Apple MacBook Pro')])[2]").click()

Related

VSCode React Native Extension Question - Vector Icons

Can someone please tell me how to get this menu that appears after highlighting this part of the string as seen in this picture I'm including? I'm setting up vector icons for my app using react native cli. Your help will mean the world.
Not sure if the picture link works, but basically after writing this string in the app.js file of my app, he highlights "AntDesign", which then bring a little dropdown menu with an option to "Insert "import AntDesign from 'react-native-vector-icons'" Here is the string that I typed out:
<AntDesign name={"stepforward"} size={30} />
Again, he then highlights "AntDesign" which brings up a dropdown menu with that option mentioned above. I do not get this.
enter image description here

Enter text in a Read only text field in Robot Framework

Using robot framework(with java) I need to pass the file path in a text field to upload the file. However, when i click on the text field it opens the File upload window pop up. In the DOM the field is marked as read only.Below is the screenshot of the DOM for the mentioned element.
enter image description here
Is there a way i can enter file path in to the read only text box?

How to get text from a primefaces component with selenium web driver

I'm automating a system made in Primefaces and I'm having trouble finding elements.
Case 1.
I want to get the text of this span that is inside the li.
I want to get the text circled in red
I'm using this code. but I get the element not found error.
String textoErro = driver.findElement(By.xpath("//*[#id=\"messagesCargoFuncaoCU\"]/div/ul/li[1]/span")).getText();
Case 2.
I want to get the contents of the td.
I want to get the text circled in red. "AutomacaoTeste"
I'm using this code.
But I get the error: Unable to locate element.
String textoName = driver.findElement(By.xpath("//*[#id=\"dataTableAgfolhaCargoFuncao_data\"]/tr/td[3]/span")).getText();

How to get the text from the auto suggestion of the auto complete text box?

My requirement is I want to select the particular name from the auto-suggestion in the autocomplete text box.
So here I only know how to get the name by using the mouse down to achieve this But I know it's not a good solution to get that because we don't give the guarantee to the auto-suggestion is same as all the time in the browser.
So if anyone knows how to get the auto-suggested text names for the auto-complete text box in Selenium Web Driver using Junit (Here I am using the Junit in Selenium WebDriver to develop the automation test script).
My code:
driver.findElement("//input[#id='phSearchInput']").SendKeys(KEYS.ARROW_DOWN);
Thread.sleep(1000);
driver.findElement("//input[#id='phSearchInput']").SendKeys(KEYS.ARROW_DOWN);
Thread.sleep(1000);
driver.findElement("//input[#id='phSearchInput']").SendKeys(KEYS.ENTER);
Here the above code is only working for my correct option is shows as
the second option of the auto-suggested texts.
So that's why I need how to get the text names in the auto-suggestion for the autocomplete text box.
Please the give the solutions as the JUnit Form to my question because I am using the JUnit to develop the automation test script.
Thanks
The auto-suggest box is HTML like anything else on the page. Create a locator that finds the auto-suggest panel and then parse the contents. Once you figure out the structure, you can get the text that you need and then assert that it is correct.
I can't see the full HTML from your screenshot but you can see that the list is contained in an HTML UL. The UL is the container and each LI is a list item in the dropdown. You can use that info to do something like
ul.autoCompleteGroup > li
to get all the list items. I can't see what's inside of there but at some point you should be able to use .getText() to get the auto suggest items. From there you just compare what you pulled off the list to what you are expecting with an Assert.
Please try below code
public void selectAutoCompleteItem(String itemText) {
String xpathPattern = "//div[#id='phSearchInput_autoCompleteBoxId']" +
"//ul/li/a[.='%s')]";
String xpathExp = String.format(xpathPattern, itemText);
driver.findElement(By.xpath(xpathExp)).click();
}
In that case you can use the findelements functionality. So you can say:
List<WebElement> elements = driver.findElements(by.xpath("//a[#class='autoCompleteRowLin‌​k']");
And then for
each list item you can use getText to get the exact text. Then you can assert it with the expected values

Selenium Click Image Link based on Alt (including quote)

I have a tricky one!
I am trying to test an image button click in Selenium. This is the HTML code:
<img src="/img/buttons/showOnOrder.gif" alt="Show 'On Order'"/>
I completely agree that having the single quote in the alt text is not ideal/good, but for the purposes of this test, I can't currently change the code.
I have tried the following
selenium.click("//img[#alt=\"Show 'On Order'\"]");
selenium.click("xpath=//img[#alt='Show ''On Order''']");
But no joy. Please, please, please make my day and suggest the syntax I can use that works.
Try this :
selenium.click("//a[contains(#href,'onOrder')]/img");
Try like this
selenium.click("//img[contains(#alt,'Show') and contains(#alt,'On Order')]");
or
selenium.click("xpath=//img[#alt='Show \'On Order\'']");
or
selenium.click("css=img[alt*='Show'][alt*='On Order']");

Categories

Resources