Hello I'm new using selenium and I was trying to execute some tests from a web page.
This is my code:
System.setProperty("webdriver.gecko.driver","C:\\DRIVERS\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
//Open Portal Fiscal
driver.get("http://150.23.110.111/Retenciones/");
//Find what field and enter the user and password
driver.findElement(By.id("frmLogin:txtUsr")).sendKeys("arrubio");
driver.findElement(By.id("frmLogin:txtPwd")).sendKeys("gnp00gnp");
driver.findElement(By.id("frmLogin:butLogin")).click();
Actions action = new Actions(driver);
WebElement we = driver.findElement(By.xpath(""));
action.moveToElement(we).moveToElement(driver.findElement(By.xpath("")));
I can enter to the page without problem and I can enter the user and the password to login, but there's a hoover menu on the next page that I can´t use and stops my automatic execution.
This is the xpath and the csspath:
xpath: /html/body/div[3]/div/div/form/div/ul/li[1]/ul/li[1]/a/span
csspath: html body div#content div#leftPanel.ui-layout-unit.ui-widget.ui-widget-content.ui-corner-all.ui-layout-west.blankBck div.ui-layout-unit-content.ui-widget-content form#j_id1833690111_27e067e8.blankBck div#j_id1833690111_27e067e8:j_id1833690111_27e0678e.ui-menu.ui-menubar.ui-widget.ui-widget-content.ui-corner-all.ui-helper-clearfix ul.ui-menu-list.ui-helper-reset li.ui-widget.ui-menuitem.ui-corner-all.ui-menu-parent.ui-menuitem-active ul.ui-widget-content.ui-menu-list.ui-corner-all.ui-helper-clearfix.ui-menu-child.ui-shadow li.ui-menuitem.ui-widget.ui-corner-all a.ui-menuitem-link.ui-corner-all span.ui-menuitem-text
And this is the element that appears inspecting the "Búsqueda" button.
<ul class="ui-widget-content ui-menu-list ui-corner-all ui-helper-clearfix ui-menu-child ui-shadow" role="menu" style="display: block; height: auto; z-index: 1013; left: 0px; top: 28px;">
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
<a class="ui-menuitem-link ui-corner-all" href="/Retenciones/main/faces/m_evaPuntual.xhtml" style="width:120px" tabindex="-1">
<span class="ui-menuitem-text">Búsqueda</span>
</a>
</li>
<li class="ui-menuitem ui-widget ui-corner-all" role="menuitem">
</ul>
How can I select and open the button "Búsqueda" from the hoover menu?
Thanks for the attention :)
try using:
Actions action = new Actions(driver);
WebElement menu = driver.findElement(By.xpath("xpath for menu"));
WebElement item = driver.findElement(by.cssSelector("css selector values for Búsqueda"));
action.moveToElement(menu).moveToElement(item ).click().build().perform();
Try this below code using action class
WebElement menu_element = driver.findElement(By.xpath("your_menu_xpath"));
WebDriverWait wait = new WebDriverWait(driver, 10); //Explicit wait method, wait for web-element till 10 seconds so, your driver should able to find the web-element.
wait.until(ExpectedConditions.elementToBeClickable(driver.findElement(By.xpath("Your_submemu_xpath"))));
WebElement sub_menu_element = driver.findElement(By.xpath("Your_submemu_xpath"));
Actions action = new Actions(driver);
action.moveToElement(menu_element).moveToElement(sub_menu_element).click().build().perform();
Explanation:
1) First locate the menu element
2) Provide explicit wait method for few seconds so your driver may able to find the sub_menu_element that you want to go with.
3) After explicit wait locate the sub_menu element, that you want to go with.
4) Using Action class try to move element from menu to sub menu.
Related
I am trying to select an option from a drop-down that does not populate until the locator has been clicked. This my solution but it's not working.
List<WebElement> options = driver.findElements(By.cssSelector("mat-select"));
for (WebElement option : options) {
if (option.getAttribute("ng-reflect-value").contentEquals("50757")) {
Actions build = new Actions(driver);
build.moveToElement(option).click().build().perform();
}
}
HTML of the dropdown.
<div role="listbox"
tabindex="-1"
class="ng-tns-c114-22 ng-trigger ng-trigger-transformPanel mat-select-panel mat-primary"
id="mat-select-0-panel"
aria-multiselectable="false"
aria-labelledby="mat-form-field-label-27"
style="transform-origin: 50% 22px 0px; font-size: 15px; opacity: 1; min-width: calc(100% + 32px); transform: scaleY(1);">
<mat-option
_ngcontent-tqo-c274=""
role="option"
class="mat-option mat-focus-indicator mat-active ng-tns-c114-22 ng-star-inserted"
ng-reflect-value="50757"
id="mat-option-0"
tabindex="0"
Please try with the below code: If possible please share the application URL then I can replicate it from my side.
WebElement option = driver.findElement(By.xpath("//mat-
option[contains(text(),'option text')]");
driver.waitUntilElementVisible(option, 10);
driver.findElement(option).click();
Also please refer link for more details on selecting a particular value in a dropdown without using the methods of Select class in Selenium
I have an element on a website which looks like below
<div id="wrapperCategory" class="categoryItemWrapper">
<div class="panel panel-default panel-categoryItem text-center categoryItem disabledItem" ng-class="category.CategoryStyleClass" ng-click="setselectedProduct(productIndex,product,category); setselectedProductAmount(null);" title="Category">
<div class="panel-heading">
Category
</div>
<div class="panel-body">
Price
</div>
<div class="panel-footer availability" ng-class="category.AvailabilityStyleClass">
<span ng-bind-html="category.AvailabilityText">Avail</span>
</div>
</div>
</div>
I need to click on it to get forward. If I manually click on each of these divs or on span website goes forward but SeleniumWebdriver can't click any of them.
I tried click on span and on div with ng-click event buch each time i get an error:
Exception in thread "main" org.openqa.selenium.WebDriverException: Element <div class="panel panel-default panel-categoryItem text-center categoryItem" ng-class="category.CategoryStyleClass" ng-click="setselectedProduct(productIndex,product,category); setselectedProductAmount(null);" title="Category"></div> is not clickable at point (619.2666625976562, 474.23333740234375). Other element would receive the click: <div style="top: 0;left: 0;bottom: 0;right: 0;position: fixed;pointer-events: auto !important;z-index: 10000;" id="cover-1526454140024"></div>
I don't get it.
Can I somehow check which element is clickable and which element overlaps this which I want to click (I dont'see any div with id="cover-1526454140024" in code of the website) ?
Updated:
Unfortunately it still doesn't work after your solutions.
The same exception when trying to click.
// try {
// Thread.sleep(1000);
// } catch (InterruptedException e) {
// e.printStackTrace();
// }
JavascriptExecutor js = (JavascriptExecutor) Mundial.driver;
js.executeScript("arguments[0].scrollIntoView();", categoryItem);
new WebDriverWait(driver, 10).until(ExpectedConditions.elementToBeClickable(categoryItem));
categoryItem.click();
List<WebElement> selects = driver.findElements(By.tagName("select"));
Select ticketsToSelect = new Select(selects.get(3));
ticketsToSelect.selectByValue("number:2");
It only works in case when I put sleep and scroll down manually. I don't get it.
As per your response :
You will have to scroll down to let the web element available to your script.For that you can use this code :
public static void scrollDown(WebDriver driver, String YoffSet){
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript(YoffSet);
}
here you can call this method anywhere from your code.
Then you can use this code to interact with the web element :
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("static ID")));
element.click();
I experienced lot of such issues, as Ankur says, use wait before click
WebElement seems_unclickable = wait.until(ExpectedConditions.elementToBeClickable(By.id(...
One of the way is ExpectedConditions commands
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("Yourid")));
More examples can be found at http://toolsqa.com/selenium-webdriver/wait-commands/
Try "scrollIntoView".
public void ScrollElementIntoView(IWebElement element)
{
var js = driver as IJavaScriptExecutor;
js.ExecuteScript("arguments[0].scrollIntoView()", element);
}
I had the same issue and it was due to a having a non 100% zoom applied to the page body like:
body {
zoom: 90%;
}
Removing the css zoom fixed the issue.
Very new to automation and have not had issues until now
I have a button that once clicked , a pop up button appears which one could click and it would perform a certain action.
I get to the second button and it seems to click it , however it does not perform the relevant action
My Code
//First Button//
WebElement AddUserSelect =
chromeDriver.findElementBy.id(
"j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt280_menuButton"));
AddUserSelect.click();
try {
Thread.sleep(1000L);
} catch (InterruptedException e) {
e.printStackTrace();
}
// Second Button//
WebElement AddUser =
chromeDriver.findElement(By.id(
"j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt281"));
AddUser.click();
Element on page when I inspect
<a
id="j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt281"
class="ui-menuitem-link ui-corner-all" href="#"
onclick="PrimeFaces.ab({s:"j_idt67:j_idt68:j_idt69:j_idt229:pendingTable:dataTable:0:j_idt281",p:"j_idt67",u:"j_idt67",f:"j_idt67"});return false;"
>
<span class="ui-menuitem-icon ui-icon ui-icon-extlink"></span>
<span class="ui-menuitem-text">
Add
</span>
</a>
Any Assistance would be appreciated..Thank you
As per the HTML you have shared you target the second inner span tag and can use the following Locator Strategy to click on the intended element :
chromeDriver.findElement(By.xpath("//a[#class='ui-menuitem-link ui-corner-all' and starts-with(#id,'j_idt')]//span[#class='ui-menuitem-text']")).click();
Update A
As per your comment update as the previous line of code locates the element, however does not action as an alternative you can use the Javascript Click as follows :
WebElement elem = chromeDriver.findElement(By.xpath("//a[#class='ui-menuitem-link ui-corner-all' and starts-with(#id,'j_idt')]//span[#class='ui-menuitem-text']"));
driver.executeScript("arguments[0].click();", elem);
Update B
Induce a waiter through WebDriverWait as follows :
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='ui-menuitem-link ui-corner-all' and starts-with(#id,'j_idt')]//span[#class='ui-menuitem-text']"))).click();
I am trying to perform drag and drop action on element but its not happening.
This is the snippet of the page I am working on. Here I am trying to drag and place the Tile "Time" in position of the Tile "Approvals".
Screenshot
This is the code I am using.
Code
String sSource = "//*[#id=\"PTNUI_LAND_REC14$1_row_0"]";
String sTarget = "//*[#id=\"PTNUI_LAND_REC14$1_row_1"]";
WebElement wSource = TestBase.wDriver.findElement(By.xpath(sSource));
WebElement wTarget = TestBase.wDriver.findElement(By.xpath(sTarget));
Actions aActions = new Actions(TestBase.wDriver);
Action aDragAndDrop = aActions.clickAndHold(wSource).moveToElement(wTarget).release(wTarget).build();
aDragAndDrop.perform();
HTML
Source Element
<div class="ps_grid-row nuitile rsz_w1 rsz_h1" id="PTNUI_LAND_REC14$1_row_0" tx="1.0577777777777777" ty="1" gx=".1.0577777777777777." gy=".1.">
<div class="ps_grid-cell">
<div id="win0divPTNUI_LAND_REC_GROUPLET$13" class="ps_box-group psc_layout nuilp " tabindex="0" draggable="true" aria-dropeffect="move" aria-grabbed="false" droppable="true">
<h2 class="ps_groupleth"><span class="ps-label" id="PTNUI_LAND_REC_GROUPLET_LBL$13">Approvals</span></h2>
Target Element
<div class="ps_grid-row nuitile rsz_w1 rsz_h1" id="PTNUI_LAND_REC14$1_row_1" tx="2.057777777777778" ty="1" gx=".2.057777777777778." gy=".1.">
<div class="ps_grid-cell">
<div id="win0divPTNUI_LAND_REC_GROUPLET$14" class="ps_box-group psc_layout nuilp " tabindex="0" draggable="true" aria-dropeffect="move" aria-grabbed="false" droppable="true">
<div id="win0groupletPTNUI_LAND_REC_GROUPLET$14" class="ps_box-grouplet"><img id="PT_PORTAL_CLEAR_DOT$14" class="ps_process" src="/cs/p91h25r2x/cache/PT_PORTAL_CLEAR_DOT_1.gif" alt=""></div>
<h2 class="ps_groupleth"><span class="ps-label" id="PTNUI_LAND_REC_GROUPLET_LBL$14">Time</span></h2></div></div>
Please let me know if you require any more details.
May be you have to target on draggable elements as given below.
String sSource = "//*[#id=\"win0divPTNUI_LAND_REC_GROUPLET$13"]";
String sTarget = "//*[#id=\"win0divPTNUI_LAND_REC_GROUPLET$14"]";
WebElement wSource = TestBase.wDriver.findElement(By.xpath(sSource));
WebElement wTarget = TestBase.wDriver.findElement(By.xpath(sTarget));
Actions aActions = new Actions(TestBase.wDriver);
aActions.dragAndDrop(wSource, wTarget).build().perform();
To Drag and Drop the Tile Approvals in position of the Tile Time you can use the following code block :
WebElement from = TestBase.wDriver.findElement(By.xpath("//div[#class='ps_box-group psc_layout nuilp ' and contains(id,'win0divPTNUI_LAND_REC_GROUPLET$13')]"));
WebElement to = TestBase.wDriver.findElement(By.xpath("//div[#class='ps_box-group psc_layout nuilp ' and contains(id,'win0divPTNUI_LAND_REC_GROUPLET$14')]"));
new Actions(TestBase.wDriver).dragAndDrop(from, to).build().perform();
System.out.println("Drag and Drop Completed");
This is the code which I was trying to execute.
driver.get("https://easemytrip.com/");
driver.findElement(By.id("ddate")).click();
driver.findElement(By.id("img2")).click();
I am unable to click on the next month of the calendar. Here is the HTML code.
<div class="month">
<div id="dvprevious" class="dvnxt" runat="server">
<img id="img2" onclick="return FillcalendarV(03,2017);" alt="Arrow" src="img/left.png"/>
</div>
<div class="month2">Apr 2017</div>
<div class="month3">
<img id="img1" onclick="return FillcalendarV(05,2017);" alt="Arrow" src="img/right.png"/>
</div>
</div>
My two work arounds were to force a mouse click on the item location.
WebElement elem = driver.findElement(By.id("id"));
Actions action = new Actions(driver);
action.moveToElement(elem).perform();
action.moveToElement(elem).click().perform();
or
driver.findElement(By.id("id")).sendKeys(Keys.ENTER);
The problem is that it takes a second for the calendar popup to get rendered so you need a brief pause. The next problem I ran into is that you apparently can't click the > img because it's blocked by the container DIV. So, I just clicked the container DIV and it worked. The code below works.
driver.get("https://easemytrip.com/");
driver.findElement(By.id("ddate")).click();
new WebDriverWait(driver, 3).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("div.month3"))).click();
Following code will work.
WebElement ele1 = driver.findElement(By.id("dvfarecal"));
ele1.click();
WebDriverWait wait = new WebDriverWait(driver, 5);
WebElement ele2 = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//img[#src='img/right.png']")));
ele2.click();
driver.manage().timeouts().implicitlyWait(3, TimeUnit.SECONDS);
WebElement date = driver.findElement(By.id("snd_3_10/05/2017"));
date.click();