How to write automated code in selenium to user role drop down in Admin portal in OrangeHRM - selenium-webdriver

Error:
org.openqa.selenium.support.ui.UnexpectedTagNameException: Element should have been "select" but was "div"
My code:
WebElement button1=driver.findElement(By.xpath("//*[#id=\"app\"]/div[1]/div[2]/div[2]/div/div[1]/div[2]/form/div[1]/div/div[2]/div/div[2]/div/div/div[2]/i"));
button1.click();
WebDriverWait wait2 = new WebDriverWait(driver, 30);
wait2.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"app\"]/div[1]/div[2]/div[2]/div/div[1]/div[2]/form/div[1]/div/div[2]/div/div[2]/div/div/div[1]")));
Select user_role_dropdown = new Select(driver.findElement(By.xpath("//*[#id=\"app\"]/div[1]/div[2]/div[2]/div/div[1]/div[2]/form/div[1]/div/div[2]/div/div[2]/div/div")));
user_role_dropdown.selectByVisibleText("Admin");

Related

Hover Electronics -> Mobiles and Click using Selenium in Flipkart UI using Chrome

Actions action = new Actions(driver);
WebElement we = driver.findElement(By.xpath("//*[#id=\"container\"]/div/div[2]/div/ul/li[1]/span"));
action.moveToElement(we).moveToElement(driver.findElement(By.xpath("//*[#id=\"container\"]/div/div[2]/div/ul/li[1]/ul/li/ul/li[1]/ul/li[1]/a[#href='/mobile-phones-store?otracker=nmenu_sub_Electronics_0_Mobiles']"))).click().build().perform();
I am trying to hover and click using xpath. The code is not throwing any error but it is still unable to perform click option after hover.
Try with the below code snippet. I have tested it with chrome driver and works fine.
WebElement electronics_menuname = driver.findElement(By.xpath("//span[contains(text(),'Electronics')]"));
Actions builder = new Actions(driver);
builder.moveToElement(electronics_menuname).build().perform();
WebElement mobile_menu_button = driver.findElement(By.xpath("//li[#class='_1KCOnI _2BfSTw _1h5QLb _3ZgIXy']//a[contains(text(),'Mobiles')]"));
new WebDriverWait(driver,20).until(ExpectedConditions.elementToBeClickable(mobile_menu_button)).click();

Have to double click the buttons on a webpage while using selenium webdriver

I am using this code to click on on a button
driver.findElement(By.linkText("Sign up")).click();
I tried using:
new WebDriverWait(driver,30).until(ExpectedConditions.elementToBeClickable(By.linkText("Sign up")))
but it did not work.
Try this sample as you does not mention URL:
WebDriver driver =new FirefoxDriver();
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
driver.get("http://only-testing-blog.blogspot.in/2014/09/selectable.html");
WebElement ele = driver.findElement(By.xpath("//button[contains(.,'Double-Click Me To See Alert')]"));
//To generate double click action on "Double-Click Me To See Alert" button.
Actions action = new Actions(driver);
action.doubleClick(ele);
action.perform();
Go through this URL to learn more:
http://www.software-testing-tutorials-automation.com/2015/01/double-click-on-button-using-actions.html

Unable to automate the Popup in selenium

i am unable to identify the web elements when a pop up is displayed on clicking "select your family members" in the below website, i am not sure how to automate this ?
I have tried using Switch window and alert windows.
http://health.policybazaar.com/?utm_content=home_v3
There is no need to switch any window , Use following code
driver.get("http://health.policybazaar.com/?utm_content=home_v3");
driver.manage().window().maximize();
driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);
driver.findElement(By.id("input_6")).click();
Updated :
WebDriverWait wait =new WebDriverWait(driver, 120);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[#class='prequote-member-left-section']/md-checkbox[#name='checkboxSelf']/div[1]")));
driver.findElement(By.xpath("//div[#class='prequote-member-left-section']/md-checkbox[#name='checkboxSelf']/div[1]")).click();
Note : Use ExplicitWait to make element visible on next popup and then click

Selenium WebDriver-Chrome

Hi all i am using selenium backed webdriver i am automating some third party site so i don't have any access to the code of that site problem is that my selenium test case works well firefox but when i use chromedriver it gives an exception Element is not clickable at point (693, 14). Other element would receive the click i read on some blog that using the lines of code makes the problem go the lines are given below
WebDriverWait wait=new WebDriverWait(driver, 20);
WebElement element=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id='sendFile']")));
element.click();
But still face same issue.
Someone please help me to resolve this issue. Thanks..
Try with JavascriptExecutor as below:-
WebDriverWait wait = new WebDriverWait(driver, 20);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[#id='sendFile']")));
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", element);
Hope it will work...:)

Is drag-and-drop possible in chrome-webdriver?

I cannot get drag-and drop working with the Java Junit WebDriver bindings. I am working with Google Chrome on Windows.I have used below code,but i did not work.
{WebElement draggable = driver.findElement(By.id("source"));
WebElement to = driver.findElement(By.id("target"));
Actions builder = new Actions(driver);
builder.dragAndDrop(element, to).build().perform();
builder.clickAndHold(element).moveToElement(to).release(to).build().perform();}
Please try the following solution (it works for us):
WebElement dragArea = driver.findElement(By.cssSelector("#" + idDragProduct"));
WebElement to = driver.findElement(By.cssSelector("#" + idTarget));
new Actions(driver).clickAndHold(dragArea).moveToElement(to).release().build().perform();
In case you want to try and test drag-and-drop as functionality, it's not neccesary to move it to another element.
You can do:
WebElement to = driver.findElement(By.cssSelector("#" + idTarget));
new Actions(driver).clickAndHold(dragArea).moveByOffset(X_OFF,Y_OFF).release().build().perform();

Resources