Selenium , Automation, webdriver - selenium

I have web application,It works only in edge browser with IE mode.In that I am unable to automate drop-down field,So I need code to automate the drop-down field using selenium web driver.

If I understood what are you looking for...
I wrote it in C#.
using OpenQA.Selenium.Support.UI
IWebElement dropdownElement = driver.FindElement(By.Name("country code"));
//create select element object
SelectElement selectElement = new SelectElement(dropdownElement);
//select by value
selectElement.SelectByValue("NIR");
// select by text
selectElement.SelectByText("Northern Ireland");

Related

How to select dynamic list values based on JS react with Selenium Webdriver and Java?

I am trying to select first value with selenium web driver and java from drop down list values build on js , I'm getting some problems to allocate list that is dynamic and not presented in Dom .
I am tried to allocate manually and with recorder but its not work for me .
How should selector looks like to be ?
css,xpath ?
screen shot of web page
Basicaly there are two approaches using selenium webdriver.
if the "Princess" is a webelement (you can inspect it), you need to find and click the dropdown webelement first and than find and click webelement "Princess"
if the "Princess" is not a webelement (unable to inspect), you need to Select it:
new Select(LOCATOR OF THE DROPDOWN).selectByValue("Princess");

Selenium WebDriver -- Unable to click on hyperlink, click goes to the other element

I am unable to click on Website hyperlink, the click goes to Recently used pages.
Tried with CSS locator of Website icon [which works in the lower environment as it doesn't have Recently used pages] reference in it.
Tried with XPath Locator[including custom XPath], still, the click goes to another item.
Tried name locator.
Used Actions class for clicking.
Allowed the page to load completely by using sleep and WebDriver wait.
Located the element and send Enter keys, still Recently used pages is clicked.
Tried to click it using coordinates.
Thought of ChromeDriver issue but the issue persists in Firefox too.
Tried below XPath:
html/body/div/div[2]/div[2]/div[1]/a/div
//div[2]/div/a/div
Code snippet:
WebElement elementToClick = driver.findElement(By.cssSelector(".icon.siteadmin"));
elementToClick.click();
WebElement elementToClick = driver.findElement(By.cssSelector(".icon.siteadmin"));
(JavascriptExecutor)driver).executeScript("window.scrollTo(0,"+elementToClick.getLocation().x+")");
elementToClick.click();
WebElement elementToClick = driver.findElement(By.cssSelector(".icon.siteadmin"));
Actions actions = new Actions(driver);
actions.moveToElement(elementToClick);
actions.click().perform();
Actions builder = new Actions(driver);
builder.moveToElement(elementToClick, 40, 207).click().build().perform();
Result: It clicks on Recently Used Pages, and it yields a result of Recently used pages instead of Website.
UI Reference
Development Code Snippet
Hope It Helps you:
.//div[#id='box_2']/a/div[#class='icon siteadmin']/div[1]
Try the following:
driver.findElement(By.XPath(“//a[contains(#title, ‘Websites’)]”)).click()
If this doesn’t work use the above XPath in combination with one of the moves to element paths above and then use click.

Access new window elements through selenium RC

I am new to Selenium. This is my first attempt. And I want to access the Elements in the new window through Selenium RC. I have a page with a hyper link clicking on it will open new page. I want to enter username and password elements in the new window. Html Code is
Employee Login
and the new page elements are "emailAddress" and "password" for login.
My selenium code is
public static void main(String args[]) throws Exception
{
RemoteControlConfiguration rc=new RemoteControlConfiguration();
rc.setPort(2343);
SeleniumServer se= new SeleniumServer(rc);
Selenium sel=new DefaultSelenium("localhost",2343,"*firefox","http://neo.local/");
se.start();
sel.start();
sel.open("/");
sel.windowMaximize();
//sel.wait(1000);
sel.click("empLogin");
//sel.wait(2000);
//sel.openWindow("http://myneo.neo.local/user/login", "NewNeo");
//sel.waitForPopUp("NewNeo", "1000");
//sel.selectWindow("id=NewNeo");
Thread.sleep(20000);
sel.type("emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("password", "xxxxxxxx");
}
First I tried with normal approach, where it failed to identify the elements. Then I tried with open window and selectWindow options, where it through errors like
"Exception in thread "main" com.thoughtworks.selenium.SeleniumException: ERROR: Window locator not recognized: id
at com.thoughtworks.selenium.HttpCommandProcessor.throwAssertionFailureExceptionOrError(HttpCommandProcessor.java:109)
at com.thoughtworks.selenium.HttpCommandProcessor.doCommand(HttpCommandProcessor.java:103)
at com.thoughtworks.selenium.DefaultSelenium.selectWindow(DefaultSelenium.java:377)
at Demo.main(Demo.java:24)"
Some one told me that it is not possible with Selenium RC. It can achieved through Selenium Webdriver only. Is it true?
Please Help,
Thanks in Advance.
Selenium RC is not maintained anymore, I would recommend you to use WebDriver instead. Selenium RC is a Javascript application where as WebDriver uses browsers Native API. Therefore browser interactions using WebDriver are close to what the real user does. Also WebDriver's API is more intuitive and easy to use in my opinion. I don't see HTML in your question, but you could do start with something like this,
WebDriver driver = new FirefoxDriver();
WebElement login = driver.findElement(By.id("empLogin"));
login.click();
I will say, do as #nilesh stated. Use Selenium WebDriver.
Answer to your specific problem though:
You are failing at this line because you are not specifying a selector strategy.
sel.click("empLogin");
If the id attribute is empLogin then do
sel.click("id=empLogin");
There are other selector strategies you can use:
css=
id=
xpath=
link=
etc...
You can see the full list here.
You will also fail here due to the same issue:
sel.type("emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("password", "xxxxxxxx");
Put a selector strategy prefix before those fields.
sel.type("name=emailAddress", "kiranxxxxx#xxxxxx.com");
sel.type("name=password", "xxxxxxxx");

Selenium sendText

I need to preface this with "I am a noob".
In WatiN I was able to use sendText("text"); which would send the whole text rather than typing it out one character at a time which is what sendKeys() does. I have looked quite a bit for a sendText() option in Selenium and cannot seem to find anything which works.
Is there a sendText() option for selenium, if so could you provide a code example?
In Selenium RC (the older JavaScript-fueled Selenium that is no longer actively developed), there is the type() method.
In WebDriver (also known as Selenium 2), there's no such thing. However, you can easily emulate it via JavaScript:
// only if your driver supports JavaScript
JavascriptExecutor js = (JavascriptExecutor)driver;
WebElement elem = driver.findElement(By.whatever("something"));
js.executeScript("arguments[0].value = 'some text'", elem);

Selenium WebDriver Issue with cssSelector

I am trying to click on a button with using a CSS selector in Selenium 2.0 WebDriver. The issue is the script which I am able to run with Selenium RC is not working with WebDriver.
Code:
Selenium RC:
selenium.click("css=.gwt-Button:contains('Run Query')");
which works absolutely fine.
Selenium WebDriver:
driver.findElement(By.cssSelector(".gwt-Button:contains('Run Query')")).click();
which does not work.
I am using: selenium-server-standalone-2.9.0.jar with Firefox version 5.0. Could anyone help me in figuring out why the cssSelector is not working with WebDriver?
'Contains' is being deprecated from CSS 3. Webdriver supports whatever natively supported by the browser. It works in selenium RC because RC uses Sizzle library for css selectors and it supports 'contains'. Did you try something like,
WebElement element = driver.findElement(By.cssSelector(".gwt-Button[type='button']");
element.click();
If this is not unique then perhaps you might need to filter it further down. If your site uses jQuery then you could use 'contains' selector from jQuery.
JavascriptExecutor js = ((JavascriptExecutor)driver);
WebElement element = (WebElement) js.executeScript("return $(\".gwt-Button:contains('Run Query')\")[0];");
element.click();
that syntax looks valid and when I dropped some elements on a test page and then went to my console and did $(".gwt-Button:contains('Run Query')").length I got a 1 when I changed the text of the buttons. So the only thing I can think of is maybe you have a Run Query button that exists on the page but isn't displayed and so you get the runtime exception. You might want to do a check to see if it's displayed before clicking on it. Or creating a list of the elements and then removing all hidden (display == false) elements.