Selenium Select2 command for drop-down box - selenium

am new to selenium and in my previous question Selenium IDE command for input type hidden it is using select2 please help me with the command to selection option for drop-down list.
i tried looking in here https://gist.github.com/3683275 but it doesn't seem to work for me
mouseDown('//a[#class="select2-choice select2-default"][1]')
mouseUp('//li[contains(#class,"select2-result")][1]')

These commands open the options list, wait for it to appear, and finally choose the option labelled "California". Select2 can be customized in different ways, hope these commands work for you.
mouseDown css=.select2-choice > div > b
waitForVisible css=.select2-results
mouseUp css=.select2-result-label:contains('California')

WebElement element = driver.findElements(By.xpath(/*xpath*/));
Select select = new Select(element);
select.selectByVisibleText(value);

Alternatively, it can also be handled by using clickAt()
clickAt('//a[#class="select2-choice select2-default"][1]');
waitForVisible("css=.select2-results");
clickAt('//li[contains(#class,"select2-result")][1]');

Related

Data-driven dropdown menu Katalon Automation Recorder

I'm trying to automate click with Selenium IDE. I was trying to figure out if I can use the "Select" command, but it didn't work.
I would like to click on the value on the dropdown that I put in my CSV file. Like I want a specific value of the dropdown for each line of my CS.
Here's the code.
Katalon [WebUI] Select is meant only to select default html select component. Yours is custom select box.
You need to select that exactly same way as you do manually like
Click the menu
Wait for dropdown to be visible
Select the particular value based on name from your csv
Based on your html, your Katalon script will be like this,
TestObject menu = new TestObject('Menu').addProperty('css', ConditionType.EQUALS, "div.md-select-menu-container")
WebUI.click(menu)
TestObject dropdownValue = new TestObject('DropDownValue').addProperty('xpath', ConditionType.EQUALS, "//md-option[contains(text(), 'AVAN - Advancè')]")
WebUI.waitForElementVisible(dropdownValue, 30)
WebUI.click(dropdownValue)

How to select value from Google auto location using Selenium

How to automate this to select particular value even the dropdown list id cannot be inspected. Can anyone help me out on this?
Need to select U.S. 22 Imperial from the list
Please find the HTML snippet
I am unable to proceed more than this. Please help me out!
WebElement location = driver.findElement(By.id("selectbox-city-list2"));
location.sendKeys("us");
You could use sendKeys and send arrow down to select an option. Selecting one by one with the arrow down will highlight the value. You will be able to check the highlighted value using the CSS class of highlighting.
You can use ActionClass
using this you can move your cursor over a specific element based on coordinates and perform a click.
1.So taking the coordinates of that text box.
2.Enter the full value in the text box. ,
3.calculate a very near coordinate to that text box(so that it will be the suggestion) and perform a click.
element = xxxxxxx;
Actions builder = new Actions(driver);
builder.moveToElement(element, x_coord, y_coord).click().build.perform();

How to handle Autosuggestion text field having dropdown list in Selenium?

There is a text field called "Choose an Industry" on clicking inside it will show list of dropdown values.
Attaching the screen shot for ref
There are a couple issues with the code you posted. With a little clean up it may work but there are methods provided by Selenium via Select that you should take advantage of.
String expectedValue = "Adverstising Services";
Select dropDown = new Select(driver.findElement(By.xpath(".//*[#id='select2-chooseInd-container']")));
dropDown.selectByVisibleText(expectedValue);
You can read more about Select and the methods available in the docs, here: https://seleniumhq.github.io/selenium/docs/api/java/org/openqa/selenium/support/ui/Select.html

Unable to right click and select a value using Selenium Webdriver

I need to right click using selenium webdriver. When I right click on the date highlighted in red,I will have a menu opened from where I have to select "Show CTR Impressions Label".
I am able to right click and select "Show Impressions Label" but unable to click it.
Here is my code:
string xpath = "//div[#class='highcharts-axis-labels highcharts-xaxis-labels']/span[2]/div";
WebElement element=driver.findElement(By.xpath(xpath));
System.out.println("date="+element.getText());
Actions action= new Actions(driver);
action.moveToElement(element).contextClick(element).build().perform();
action
.sendKeys(Keys.ARROW_DOWN)
.sendKeys(Keys.ARROW_RIGHT)
.sendKeys(Keys.ENTER)
.build().perform();
Kindly suggest.Also, how can I select "Show Impressions Label" based on the text and not the arrow keys?
Any help will be appreciated.
Possible Solution Only , Based on my previous observations :: You are doing it in 2 lines. Combine this and you should be able to do so. Second perform takes focus away from element. And thus the continuity is broken.
action.moveToElement(element).contextClick(element).sendKeys(Keys.ARROW_DOWN).sendKeys(Keys.ARROW_RIGHT).sendKeys(Keys.ENTER).build().perform();

Checkbox does not get checked

Hi I am automating a webpage which contains multiple checkbox.
It clicks on a some checkbox and misses some checkbox.
This is my code.
Should I put a wait statement before the click to avoid this problem.
IWebElement ClickElement = Wait.Until((d) => webDriver.FindElement(By.Id(parameter1)));
ClickElement.Click();
Can you try making this change in your code -
In wait until function you are checking if the element exists by using findElement(By.Id(parameter1))
After finding the WebElement check if this is displayed by using isDisplayed() method with in the waitUntil function.
You can also check if it has already checked or not by using isSelected() method.