Hey guys I'm having this problem where I have a hidden select drop down where its style set to none.
<div>
<select id="selectForm" style="width: 285px; display: none;" name="formId">
<option value="36784">EMAIL 4</option>
</select>
<div class="sbox sbox_1cbc5b38 selectForm" tabindex="0" style="width: 285px;">
<div class="sbox_sel">
<div class="sbox_seltext" contenteditable="false">Report</div>
<div class="sbox_arrow"/>
</div>
</div>
<a id="previewForm" class="preview-button"/>
</div>
I was getting element not visible when I was looking By.id for the select tag. And the same error for when I was trying to click on the div. I found a way to make this drop down visible with jsExecutor. Here is my code to make this drop down visible to interact with:
public static void BatchResults(String form){
WebDriverWait wait = new WebDriverWait(driver, 60);
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("document.getElementById('selectForm').style.display='block';");
WebElement selectFormElement =
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("selectForm")));
Select selectForm = new Select(selectFormElement);
selectForm.selectByVisibleText(form);
js.executeScript("document.getElementById('selectForm').style.display='none';");
}
#Test(priority = 1)
public void runTest() {
String selectForm = "EMAIL 4";
Main.BatchResults(selectForm);
}
}
My issue is that, in jsExecutor I am setting the style to (style.display='block';) and it is bringing my underlining drop down on top of the styled drop down. Is there way to select this hidden drop down without using jsExecutor or what other option should I use? Also I cannot still select the option I want from the drop down after it is set to block and then none after selection
<ul class="sbox_opts sbox_fa9ea48e" style="width: 283px; top: 610.5px;
left: 330.333px; max-height: 54.5px; display: none;">
<li class="sbox_opt">EMAIL 4</li>
</ul>
Selenium is designed to navigate web pages the same way a user would. You should have a visible element that when interacted with (hover/click) will display the drop down. Once the drop down is displayed you can interact with the contents. Have Selenium perform the same tasks a user would have to.
Related
Could anyone please help me with selecting a value from Kendo UI MVVM drop down using Selenium Java?
<input class="k-input fieldFullWidth" autocomplete="off" style="width: 100%;" title="" role="combobox" aria-expanded="false" tabindex="0" aria-disabled="false" aria-autocomplete="both" aria-owns="ddStore_listbox" type="text">
<input id="ddStore" class="fieldFullWidth" data-role="combobox" style="display: none;" aria-disabled="false" data-bind="value: selectedAsset.StoreID, comboboxText: selectedAsset.StoreName">
I tried to use JavascriptExecutor. But, it gives me org.openqa.selenium.WebDriverException: unknown error: Cannot set property 'value' of null error.
jse.executeScript("document.getElementById('ddstore').value = '1';");
Thanks
Use ExplicitWait to wait until visibility of <input>tag element and then send your dropdown value as input
WebDriverWait wait = new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("ddStore")));
driver.findElement(By.id("ddStore")).sendKeys("dropDown_Value"); // send your dropdown value as input
`
The another alternative way is to use JavascriptExecuter as your tag contains attribute style="display: none;" so might be changes of invisibility of element
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].value='your_dropdown_value';",driver.findElement(By.id("ddStore")));
You can try the following code to select dropdown value:
Select mydrpdwn = new Select(driver.findElement(By.id("ddStore"))); //id of dropdown
mydrpdwn.selectByVisibleText("name");// Value you wanted to select
I have the following area on the HTML page:
<div class="t2-selector">
<div class="">
USA
<div>
<div>
<div>
<div class="selected" asset-id="129">Google</div>
<div asset-id="130">Microsoft</div>
<div asset-id="126">Apple</div>
</div>
</div>
</div>
</div>
<div class="inactive">
Europe
<div>
<div>
<div>
<div class="inactive" asset-id="127">BT</div>
</div>
</div>
</div>
</div>
<div class="">
Currencies
<div>
<div>
<div>
<div asset-id="135">EUR/USD</div>
<div asset-id="136" class="">GBP/USD</div>
<div asset-id="137" class="">USD/JPY</div>
<div asset-id="138" class="selected">USD/CHF</div>
<div asset-id="139">AUD/USD</div>
<div asset-id="140">USD/CAD</div>
</div>
</div>
</div>
</div>
So I need to select desired element from one of the groups (that should not be inactive, OK).
When I'm selecting a group nothing occurs, no error and I don't see the the selected group opens.
Even for a moment.
But when I'm trying to select an element in previously clicked group I receive
org.openqa.selenium.ElementNotVisibleException: element not visible
error.
So I understand that in the moment I'm clicking on desired element it is not visible since the group not appears open.
But why?
And what can I do to resolve this problem?
Currently I'm using following code:
String selectedGroup = getValue("group",'o');
String xpath1 = "//div[contains(text(),'" + selectedGroup + "')]";
driver.findElement(By.xpath(xpath1)).click();
webElement = driver.findElement(By.xpath(xpath1));
String className = webElement.getAttribute("class");
if(className.contentEquals("inactive"))
throw new ElementInactiveException("Selected group appears inactive. Exiting the test");
String optionAssetID = getValue("assetID",'o');
String xpath2 ="//div[#asset-id='" + optionAssetID + "']";
driver.findElement(By.xpath(xpath2)).click();
the error occur on the following line:
driver.findElement(By.xpath(xpath2)).click();
When clicking on a Group or hovering over it it looks in the following way:
As you can see from the code the selected / opened group receives "group-visible" class parameter.
You can hover over the drop down to open it and then click on your element
// simulate mouse movement to the dropdown
Actions actions = new Actions(driver);
actions.moveToElement(driver.findElement(By.xpath(xpath1))).perform();
// wait for the element to be visible before clicking on it
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.visibilityOfElementLocated(xpath2)).click();
You can also try to click using JavascriptExecutor
WebElement element= driver.findElement(By.xpath("Your Xpath"));
JavascriptExecutor executor = (JavascriptExecutor) driver;
executor.executeScript("arguments[0].click();", element);
Hope it will help you :)
I'm trying to select an option from a drop-down that doesnt populate until the locator has been clicked. This is what I see in Firebug:
div class="selectize-input items not-full has-options">
<input type="text" autocomplete="off" tabindex="" placeholder="523-23-XXXXX" style="width: 109px; opacity: 1; position: relative; left: 0px;">
</div>
<div class="selectize-dropdown multi form-control" style="display: none; width: 263px; top: 34px; left: 0px; visibility: visible;">
<div class="selectize-dropdown-content">
<div class="option" data-selectable="" data-value="523-23-20273">523-23-20273</div>
<div class="option" data-selectable="" data-value="523-23-20274">523-23-20274</div>
<div class="option" data-selectable="" data-value="523-23-20275">523-23-20275</div>
<div class="option" data-selectable="" data-value="523-23-20276">523-23-20276</div>
<div class="option" data-selectable="" data-value="523-23-20280">523-23-20280</div>
<div class="option" data-selectable="" data-value="523-23-202801">523-23-202801</div>
The code I have so far is:
public void selectAgentCodes(String agentCode)
{
driver.findElement(byAgentCodes).click();
new WebDriverWait(driver, 5).until(ExpectedConditions.visibilityOfElementLocated(By.className("selectize-dropdown-content")));
Select select = new Select(driver.findElement(By.className("selectize-dropwodn-content")));
select.selectByVisibleText(agentCode);
}
I get an UnexpectedTagNameException: Element should have been "select" but was "div". I'm not sure how to handle this as I've only worked with selects before.
Lets say I wanted to select "523-23-20275" for the agent code. How would I go about this?
Any help is appreciated! Thanks.
This isn't a normal drop-down select menu. Hence, using Select won't work in this case. Without seeing the complete site, I'm not sure what exactly must be done to select it.
But try simply clicking on the div element when the options in the dropdown are visible.
//I'm assuming that this will display the dropdown list
driver.findElement(byAgentCodes).click();
driver.findElement(By.xpath("//div[#data-value='523-23-20275']"));
Here, Select class wouldn't work if there is no select tag in the UI, you need to click on the main div, and then you need to click on any of the div having multiple options, it will first click on the drop down and then click on the specific element from the list,
below code will hopefully work for you....
1)firstly you need to click on this div by finding it through any of the available methods like by id, xpath, css selector,
driver.findElement(byAgentCodes).click();
clicking on this will open a dropdown list
2) repeat the same above point 1 for clicking the any of list items in dropdown
523-23-20275
That will work.
Follow the below steps to select an item under div tag:
You have to use collections object to store all child elements which are stored under same tag.
For Ex if you have below HTML structure:
<div id="Year">
<div class="abc">
<ul class = "xyz">
<li id=1>2000</li>
<li id=2>2001</li>
<li id=3>2002</li>
<li id=4>2003</li>
<li id=5>2004</li>
</ul>
</div>
</div>
Write below selenium code:
List<Webelement> lst = driver.findElements(By.xpath(<locator of child elements>));
//In this case it is //div[#id='Year']/div/ul/li
System will store all child elements in the list then you can select any element by index method using
lst.get(<index value>).click();
if you do not want to find using index but text use Iterator interface to find the element from the collection then click on that element:
Iterator<Webelement> it = lst.iterator();
while (it.hasNext()) {
WebElement wb = it.next();
if(wb.getText().equals(<Text to find in double quotes>)) {
wb.click();
break;
}
}
I am trying to automate the hover on a specified element, in my case is an specified office name.
When I hover on an office the information of it should appear.
My problem is that when I run his code:
String officeId = findElement(designOfficesPosition, num).getAttribute(ConstantsFramework.ID);
WebElement office = getSupport().getDriver().findElement(By.id(officeId));
action.moveToElement(office).build().perform();
getSupport().pause(ConstantsFramework.TIME_OUT_10_SECONDS);
I don't get any errors but I don't see the information of the office. Am I missing something? Any ideas? Thanks
UPDATE
Here you can see a piece of the html:
<div id="officesListPreview">
<div class="roundBox previewOffice officesRotator">
<h3>Office information</h3>
<p class="numbers">
<div id="OPA-AT" class="officeContainer" style="display: none;">
<div id="BPO-BG" class="officeContainer" style="display: block;">
<a class="officeLink" href="http://www.bpo.bg/" target="_blank" style="">
<div class="detailsOffice">
</div>
<div id="BOIP-BX" class="officeContainer" style="display: none;">
SOLVED
What I was missing is that there are two classes Actions and Action. I was using just Action class
This works perfectly!!
WebElement home = driver.findElement(By.xpath(//div[#id='homePage']));
Actions actions = new Actions(driver);
Action mouseOverHome = actions.moveToElement(home).build();
mouseOverHome.perform();
You can also try doing it via HasInputDevices interface.
RemoteWebElement homePage = (RemoteWebElement) driver.findElement(By.xpath(//div[#id='homePage']));
((HasInputDevices)driver).getMouse().mouseMove(homePage.getCoordinates());
I got a disabled textbox with below tags:
<div
id="writingactivityId2" class="boxSize ng-pristine ng-untouched ng-valid ng-valid-required redactor_editor writingActivityDisabled" ng-focus="editing()" redactor="" readonly="" ng-model="workInProgress.wip" required="" contenteditable="false" dir="ltr" style="height: 300px;">
</div>
and it has a child:
<p>
Automated Test 04/03/2015 15:03:43
</p>
Can any one suggest how to select the Text "Automated" Or double click/single on the text "Automated"?
I tried to point the webElement on div and on p when I tried double click it selects the whole page rather than selecting the text.
An answer will be a bit different for different OS. For win it will be like:
WebElement textElement = driver.findElement(By.cssSelector("div#writingactivityId2 p"));
Actions action = new Actions(driver);
action.click(textElement).sendKeys(Keys.chord(Keys.CONTROL, "a")).perform();
You can get to the element using, for example, a CSS selector:
WebElement p = driver.findElement(By.cssSelector("div#writingactivityId2 p"));