In selenium webdriver, I have a menu bu it is not "Select menu" so, must be clicked in normal way.
wait.until(ExpectedConditions.elementToBeClickable(diagnose_Type));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", driver.findElement(diagnose_Type));
It is saying no error but i can't complete my script that's meaning that the clicking not actually done.
while the script is running, if i click in the menu, it can select the wanted value an complete the script successfully. please any help.
Once the WebElement is returned following the criteria of elementToBeClickable you can pass the element while invoking the function executeScript() next as follows :
WebElement myElement = wait.until(ExpectedConditions.elementToBeClickable(diagnose_Type));
((JavascriptExecutor) driver).executeScript("arguments[0].click();", myElement);
Related
I have a scenario where I need to click Continue button.Even I gave print message after click function.The message is printing but the button is not clicking.I have tried java script executor,explicit wait(elementtobeclickable)But still its not clicking.What is the other solution.
This is what I have tried till now
By click_continue= By.xpath("//input[#id='btnWFContinue']");
if(driver.findElement(click_continue)!=null) {
waitVar.until(ExpectedConditions.elementToBeClickable(driver.findElement(click_continue)));
WebElement ele = driver.findElement(click_continue);
JavascriptExecutor executor = (JavascriptExecutor)driver;
executor.executeScript("arguments[0].click();", ele);
log.info("Clicked on Continue!!!");
/*
WebElement element = driver.findElement(click_continue);
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
driver.findElement(click_continue).click(); */
}else {
log.info("Continue button is not present moving to next step");
}
Open the desired page in your browser and open the browser console . Execute the below code in the same
$("input[id='btnWFContinue']").click() or document.getElementById("btnWFContinue").click()
If the element is clickable , then the above javascript command must change the webpage. Use the same in your script as well. Other there is no click event associated with your element.
try placing a wait statement before your if statement. Its possible that the code executes before the elemnt is loaded and the code jumps to the else part.
Unable to click on webelement button
I tried to click on button by mouse movement but no success
my outer html is as below :
<button class="btn btn-alt btn-small" type="button" ng-click="ecdapp.uploadBlueprintModalPopup();">
Create
</button>
button xpath is:
//*[#id="page-content"]/div[3]/button
Not seeing the full page source it's hard to tell where your XPath expression is good or not, you can try locating the button using its text instead
//button[normalize-space(text())='Create']
the normalize-space() function is used to discard heading/trailing whitespaces
It might also be the case the button is not immediately available, I would recommend considering using Explicit Wait approach via WebDriverWait class
WebElement myButton = new WebDriverWait(driver, 10)
.until(ExpectedConditions
.elementToBeClickable(By.xpath("//button[normalize-space(text())='Create']")));
myButton.click();
the above code will try to locate the aforementioned button for 10 seconds and click it as soon as it will be present/visible/clickable. Otherwise it will fail with NoSuchElementException
May be the Xpath is wrong. Try the below xpath:
//button[contains(text(),'Create')]
As you can see on the screenshot this Xpath 100% works, if you still won't be able to click on that button, then problem is not with xpath. Let me know if its still fails.
By.xpath("//button[#class = 'btn btn-alt btn-small' and #type = 'button']")
Based on your comment:
I tried this code , but unable to click . element click intercepted: Element ... is not clickable at point (293, 97). Other element would receive the click: ... (Session info: chrome=74.0.3729.169)
I pretty sure I know whats your problem, before u click on this element, something going on the page:
It says - Other element would receive the click, means there is other element above(overlapping) your button(pop up window, page is greyed out(disabled while loading, Some JS running)), so when Selenium trying to click on your button its actually clicking on that blocking element.
Try to click after Thread.Sleep(); wait 5-10 sec.
If this is the case then u need to add condition before find your button to check that element that prevent from clicking on button is disappeared then u click on it.
Try JavaScript executors as below,
WebElement element = driver.findElement(By.xpath("<xpath of button>"));
JavascriptExecutor js= (JavascriptExecutor) driver;
js.executeScript("arguments[0].click();", element);
There is somthing wrong with the page I want to test.
My first try:
When I clicked manually on a button, then I will be forwarded normally on the next page.
When I tried to click on the same button with selenium, then I get an error page "Sorry...something gone wrong...blabla". I think this problem can only solve the developer team of the page.
By book = By.cssSelector("#button\\.buchung\\.continue");
//By book = By.cssSelector("button.buchung.continue");
//By book = By.xpath("//*[#id='button.buchung.continue']");
WebElement element= ConfigClass.driver.findElement(book);
element.click();
But I want to try a workaround:
I clicked on the same button with JQuery.
I opened my chrome console and execute the button with:
jQuery('#button\\.buchung\\.continue').click()
How can I execute this JQuery expression in my selenium code?
I tried this, but without success:
JavascriptExecutor je = (JavascriptExecutor) driver;
je.executeScript("jQuery('#button\\.buchung\\.continue').click()");
Use $
je.executeScript("$('#button\\.buchung\\.continue').click()");
jQuery("selector") will return you a list.
I think you have to call click() on the element at index 0 (Assuming exactly one element satisfies the selector)
Code:
je.executeScript("jQuery('#button\\.buchung\\.continue')[0].click()");
You were pretty close. If the cssSelector is uniquely identifying the WebElement you can use the following code block :
By book = By.cssSelector("#button\\.buchung\\.continue");
WebElement element= ConfigClass.driver.findElement(book);
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);
I am trying to click on a link from a dropdown list in the menu. Selenium seems to be able to find the element. But not able to click on it and giving the below exception:
Exception in thread "main" org.openqa.selenium.ElementNotInteractableException: Cannot click on element
I am using IEDriver to run the code.
Below is the java code I am using to find and click on the element:
File file = new File("C:\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
WebDriver driver = new InternetExplorerDriver();
driver.manage().window().maximize();
driver.get("url");
driver.findElement(By.xpath("//*[#id=\"Ul1\"]/li[2]/a")).click();
driver.findElement(By.xpath("//*[#id=\"Ul1\"]/li[2]/ul/li[1]/a")).click();
Below is the HTML body:
<body><ul class="sf-menu" id="Ul1"><li class = "current"><a target="bodyFrame" href="http://hostname.default.aspx">Home</a><ul></ul></li><li class = "current">Create Usage<ul><li class="current"><a target="bodyFrame" href="../SAMPLEAPPDT/Usage.htm" title="Usage Generator (SAMPLEAPP Rating)"">Usage Generator</a> <ul></ul></li><li class="current"><a target="bodyFrame" href="../NETWORKUG/network_usage/NETWORKUsageUpload.aspx?appId=1" title="NETWORK"">NETWORK</a><ul></ul></li><li class="current"><a target="bodyFrame" href="../NETWORKUG/network_usage/NETWORKUsageUpload.aspx?appId=2" title="RSS Usage Generator"">RSS</a><ul></ul></li></ul></li></ul><iframe name="bodyFrame" id="bodyFrame" src="" width="100%" frameborder="no"></iframe></body>
Please let me know what could be the issue
Assuming you are using some JavaScript code to open/close this dropdown, you might need to wait for the dropdown to open before you can select the element because it is not yet visible. Your second "click" might be too fast after the first one.
For example, you can implicitely wait for a certain
amount of time like so:
driver.manage().timeouts().implicitlyWait(1, TimeUnit.SECONDS);
A better alternative would be to wait for your element to be visible like this:
WebDriverWait webDriverWait = new WebDriverWait(driver, 10);
webDriverWait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[#id=\"Ul1\"]/li[2]/ul/li[1]/a")));
Do this after you click the first "a" element and before you try to click on the second.
Thanks for the responses.
The issue seems to be that after selenium clicks on the menu, the list shows up and disappears again. So the second findElement i was using to click on the link in the menu dropdown was not working since selenium is not able to find the element.
I was able to resolve the issue by making selenium hover over the menu and clicking on the first link in the list
Below is the code I used:
Actions action = new Actions(driver);
WebElement webelement = driver.findElement(By.xpath("//*[#id=\"Ul1\"]/li[2]/a"));
action.moveToElement(webelement).moveToElement(driver.findElement(By.xpath("//*[#id=\"Ul1\"]/li[2]/ul/li[1]/a"))).click().build().perform();
Java with Selenium Webdriver: Unable to click On the link list but I am able to print out all the link.
I also tried to click on the link using : linktext, href,JS, xpath, CSS, action.double click and click.
//this is my code
WebElement hometab=driver.findElement(By.xpath("//*[#id='new_nav']/li[1]/a"));
hometab.click();
List<WebElement> homelist1=driver.findElements(By.xpath("//ul/ul/li[1]/ul/li/a"));
int allLinks = homelist1.size();
for(int i=0;i<=allLinks;i++) {
List<WebElement> homelis=driver.findElements(By.xpath("//*[#id='main_form']/div[2]/div/ul/ul/li[1]/ul/li"));
WebElement homelis11=driver.findElement(By.xpath("//ul/ul/li[1]/ul/li[1]"));
System.out.println(homelis.get(i).getText());
WebElement element = homelis.get(i);
System.out.println(homelis.get(i));
System.out.println(homelis.get(i).getText());
homelis11.click();
element.submit();
System.out.println("Inside action class");
Actions actions = new Actions(driver);
actions.moveToElement(homelis11).click().build().perform();
System.out.println("JS click ");
//js click
JavascriptExecutor exec = (JavascriptExecutor) driver;
exec.executeScript("arguments[0].click()", homelis11);
//verify the text on that page
WebElement textq=driver.findElement(By.xpath("//h1"));
System.out.println(textq.getText()+UIActions.tab);
//back to home page with all the menu list
driver.navigate().back();
Thread.sleep(15);
Identify the select HTML element:
WebElement mySelectElement = driver.findElement(By.id("mySelect"));
Select dropdown= new Select(mySelectElement);
or pass it directly to the Select element:
dropdown = new Select(driver.findElement(By.id("mySelect")));
To select an option you can do:
All select/deselect methods will throw NoSuchElementException if no matching option elements are found.
Select by Visible Text (select all options that display text matching the argument):
dropdown.selectByVisibleText("Italy");
or
Select by Index (select the option at the given index. This is done by
examining the “index” attribute of an element, and not merely by counting):
dropdown.selectByIndex(2);
http://loadfocus.com/blog/2016/06/13/how-to-select-a-dropdown-in-selenium-webdriver-using-java/
I am displaying a dropdown for user to select after i click signup tab. But using selenium i am not able to select any option.
driver.findElement(By.id("signup")).click();
WebDriverWait wait = new WebDriverWait(driver,15);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Select drop = new Select(driver.findElement(By.id("user_type_select")));
drop.selectByIndex(2);
The signup tab appears but the dropdown is not selected. Any ideas?
can you sure the select is ready after 10s?
try this:
waiter.until(ExpectedConditions.presenceOfElementLocated(By.id("user_type_select")));
It is always better to wait for the elements to load and javascript to execute. At the end point javascript is the last action completed by a webpage, so check for the wait time of it. Sample code below.
wait.equals((((JavascriptExecutor) driver).executeScript("return document.readyState").equals("complete")));