I have a multiselect box that I need to test. Is there a way I can ctrl + click to select multiple values from this box?
I donât think that you can perform this using the built-in keywords, you will need to use Selenium:
List<WebElement> options = WebUiCommonHelper.findWebElements(findTestObject('path/to/my/object'), 30);
Actions actions = new Actions(DriverFactory.getWebDriver());
actions.keyDown(Keys.LEFT_CONTROL)
.click(options.get(0))
.click(options.get(1))
.click(options.get(2))
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();
Your Test Object will need to identify all of the option elements, or you will need to find them another way (using Seleniumâs âSelectâ class, for example).
I hava similar problem and thought to use your solution, but sadly Iâm not god at selenium and web search
I have a table and want to select 2 elements and then click on a button.
My List:
I tried to use your mentioned code example:
List options = WebUiCommonHelper.findWebElements(findTestObject(âObject Repository/ListView/Record_Listâ), 30);
Actions actions = new Actions(DriverFactory.getWebDriver());
actions.keyDown(Keys.LEFT_CONTROL)
.click(options.get(0))
.click(options.get(1))
.click
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();
The TO âRecord_Listâ is defined as xpath (//tr[starts-with(@id,âtreeview-â) and contains(@id,â-record-rootâ)])
I thought that I have to use this TO and all following -tags would be in options[0], options[1], âŚ
But sadly it doesnât worked.
But it failed with the error âjava.lang.IndexOutOfBoundsException: Index: 1, Size: 1â â for me the List just includes one item
Next I tried to use the selenium select-class:
def driver = DriverFactory.getWebDriver()
//selenium = new WebDriverBackedSelenium(driver, baseUrl)Select oSelect = new Select(driver.findElement(WebUiCommonHelper.findWebElement(By.xpath(â//tr[starts-with(@id,âtreeview-â) and contains(@id,â-bodyâ)]â), 5)))
oSelect.selectByVisibleText(â2020190789â);
// Using sleep command so that changes can be noticed
Thread.sleep(2000);oSelect.selectByVisibleText(â2020190624â);
Thread.sleep(2000);
I got at âSelect oSelectâ the error âgroovy.lang.MissingPropertyException: No such property: By for class: Script1551953808883â â looks like it canât find the object, but the xpath is correct.
I found a third solution
WebDriver driver = DriverFactory.getWebDriver()
âTo locate tableâ
WebElement Table = driver.findElement(By.xpath(â//tr[starts-with(@id,âtreeview-â) and contains(@id,â-bodyâ)]â))
âTo locate rows of table it will Capture all the rows available in the tableâ
List rows_table = Table.findElements(By.tagName(âtdâ))Actions actions = new Actions(DriverFactory.getWebDriver());
actions.keyDown(Keys.LEFT_CONTROL)
.click(rows_table.get(0))
.click(rows_table.get(1))
.click
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();
At âWebElement Tableâ I got the error âgroovy.lang.MissingPropertyException: No such property: By for class: Script1551953808883â â but xpath is correct.
Did I forgot something, have you a hint for me?
Thanks
You just need to import the By class:
import org.openqa.selenium.By
Thanks for this hint. It helped me to identify that my xpath wasnât correct
But after correction my code looks like:
WebDriver driver = DriverFactory.getWebDriver()
âTo locate tableâ
WebElement Table = driver.findElement(By.xpath(â//tr[starts-with(@id,âtreeview-â) and contains(@id,â-record-rootâ)]â))
âTo locate rows of table it will Capture all the rows available in the tableâ
List rows_table = Table.findElements(By.tagName(âtdâ))Actions actions = new Actions(DriverFactory.getWebDriver());
actions.keyDown(Keys.LEFT_CONTROL)
.click(rows_table.get(0))
.click(rows_table.get(1))
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();
But I get this in the log after the .perform()-command:
1551982874208 Marionette WARN TimedPromise timed out after 0 ms: stacktrace:
bail@chrome://marionette/content/sync.js:196:64
Any idea?
Not sure, never seen that before, but it doesnât look like an error, just a warning. Did your script do what it was supposed to?
No, it doesnât.
There is no selection on any element.
Now I looked again on the example and changed my code as followed:
WebDriver driver = DriverFactory.getWebDriver()
âTo locate tableâ
WebElement Table = driver.findElement(By.xpath(â//tbody[starts-with(@id,âtreeview-â) and contains(@id,â-bodyâ)]â))
âTo locate rows of table it will Capture all the rows available in the tableâ
List rows_table = Table.findElements(By.xpath(â//tr[starts-with(@id,âtreeview-â) and contains(@id,â-record-â)]â))Actions actions = new Actions(DriverFactory.getWebDriver());
actions.keyDown(Keys.LEFT_CONTROL)
.click(rows_table.get(3))
.click(rows_table.get(4))
.keyUp(Keys.LEFT_CONTROL)
.build()
.perform();
And now it works.
Iâm so grr, of course I have to set the tbody to the element âWebElement Tableâ
For someone who is interested at the source of the example:
(At section âExample 1: You want to get a text from a Web table and verify it.â)
But your hint was a big step.
Thanks.
To get this to work, I had to import all of the following:
import org.openqa.selenium.By as By
import org.openqa.selenium.WebDriver as WebDriver
import com.kms.katalon.core.webui.driver.DriverFactory as DriverFactory
import org.openqa.selenium.interactions.Actions as Actions
import org.openqa.selenium.Keys as Keys
I appreciate that this is an old thread but it might be of use to others looking for a solution.
Iâve used the following built in keywords in order to select multiple values, with x, y, z being the index numbers of the options to be selected (starting from 0).
WebUI.selectOptionByIndex(findTestObject(âPromotions/AddPromotion/Select_Productsâ), âx,y,zâ)