I'm trying to find elements on below URL to perform some task, but I could not found any element on this page. So, kindly help me.
URL: https://cdns.webex.com/mw3000/mywebex/default.do?siteurl=cdns
My code is:
WebElement element = driver.findElement(By.xpath("html/body/div[1]/div[3]/table/tbody/tr/td[7]/span/a"));
System.out.println(element.getAttribute("id"));
Error which I faced :
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element.
The page you specified is made up of multiple frames. The element you are searching for is inside one of the frames. I'm not particularly familiar with Selenium, so I don't know if it supports going across frame boundaries like that, but that's where you need to start looking at least.
Related
I am trying to automate Salesforce application Using Selenium and getting NoSuchelementException though XPATH is correct and valid for particular object. When i have searched the issue, it might be reason for Shadow DOM.
For EX:
So XAPTH i have written like,
driver.findElement(By.xpath("//input[#name='Name']")).sendKeys("Jams");
or
driver.findElement(By.xpath("//input[#id='input-299']")).sendKeys("Jams");
This XPATH is highlighting in Console as well. But while automating it throws nosuchelement error.
So while checking for ShadowDOM option, am getting option like this for Name Object.
#shadow-root(user-agent)
Shadowroot DIV
-- nothing mentioned in div. it just open and closed tags.
How to automate this?
You can check if there are any iframes in your Dom. Simply do //iframe in your page developer mode(F12)> elements tab > search (Ctrf+F) area. If there are any, you will get the number of iframes.
Now if your textbox is in any of iframe use below code to go inside particular iframe first
driver.switch_to.frame("<name or Id of frame>")
then come out to frame use below:
driver.switch_to.parent_frame()
Also, if the issue is not related to frames check below for shadow-root related issue:
you can check below for shadow-root element ( Question is for Java, but you can co-relate):
How to interact with the elements within #shadow-root (open) while Clearing Browsing Data of Chrome Browser using cssSelector
The website contents are mostly created now using javascript. You may have to wait for certain elements to load before doing anything to it.
https://seleniumbyexamples.github.io/wait
I am trying to practice using Selenium by doing a simple operation of creating a custom object in Salesforce Lightning. My code works fine in Classic, but once I switch over to Lightning, for some reason it only works up to a certain point.
What works:
driver.get("http://login.salesforce.com");
driver.manage().window().maximize();
driver.findElement(By.xpath("//input[#id='username']")).sendKeys("<USERNAME>");
driver.findElement(By.xpath("//input[#id='password']")).sendKeys("<PASSWORD>");
driver.findElement(By.xpath("//input[#class='button r4 wide primary']")).click();
driver.findElement(By.xpath("//*[#id=\"oneHeader\"]/div[3]/div/div[2]/div/div/ul[2]/li[3]/div")).click();
driver.findElement(By.xpath("//*[#id=\"oneHeader\"]/div[3]/div/div[2]/div/div/ul[2]/li[3]/div/div[2]")).click();
So I am able to login and access the Object Create page just fine. The issue is with the next bit of code, which should be the easiest:
driver.findElement(By.xpath("//input[#id='MasterLabel']")).sendKeys("Address");
driver.findElement(By.xpath("//input[#id='MasterLabel']")).sendKeys("Addresses");
driver.findElement(By.xpath("//input[#value=' Save ']")).click();```
I keep getting the error message:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//input[#id='MasterLabel']"}
Things I have tried:
Searching for the input boxes via name and id instead of xpath. Same results
Tried implementing an explicit wait. Doesn't seem to make a difference
Tried doing a driver.switchTo().frame() method, but Webdriver can't seem to detect an iFrame on the
page.
Any help would be greatly appreciated! Thanks
I got stuck not just for this one case. Many cases came out with nosuchelement exception, I cannot find the reason why. I use chrome console to locate the element and it shows correct result. Is that possible something wrong with the page itself, not my script?
Context click on the element you are trying to click, and see if the element is inside any frame. Try to navigate through the tags and see if this element is under any iframe.
switch to the iframe using,
driver.switchTo().frame(driver.findElement(By.xpath("iframexpath")));
I wrote this
driver.findElement(By.xpath("//input[#type='textarea']")).sendKeys("foo");
and I got this
BrowserController.remoteControl(): Unable to locate element: //input[#type='textarea']
When you are not able to find the element it could be following reasons
Identifier you provided is wrong
element is inside some frame, in this case you will have to find that frame and switch to it.
driver.switchTo().frame(1);
website is taking sometime to load the element. in this case you could you explicit wait.
wait.until(ExpectedConditions.presenceOfElementLocated(By.id("id"));
Hej Guys
I an using google visualization api to draw stacked bar chart. Its all fine but now i want to test it with selenium but having a hard time finding the elements in the google chart.
For example i want to click on the chart element but everytime i try to find an element by xpath i get exception "OpenQA.Selenium.NoSuchElementException: The element could not be found"
I read that with selenium its tricky to click on the svg images.
Is there anybody who know a solution cuz i m kind of desprate and i havent find a suitable solution on the net by myself.
My chart looks like this:
http://i48.tinypic.com/21o4swx.png
What i am trying todo is:
webdriver.Navigate().GoToUrl("http://localhost:59777/Tests/TestsMainView");
IWebElement element = webdriver.FindElement(By.XPath("/html/body/div/div[2]/div[2]/iframe/html/body/div/svg/g[2]/g/g[2]/rect[5]"));
Actions myAction = new Actions(webdriver);
myAction.Click(element).Perform();
Thread.Sleep(9999);
Thanks :)
Here is some advice that may help you. First your second line of code is should be
WebElement element = webdriver.FindElement(By.xpath("//img[contains(#src,'http://i48.tinypic.com/21o4swx.png')]"))
You had "IWebElement" (this was probably just a typo in your question). I changed the way the element is found searching for matching element instead of starting at the top level and working down. This is a better practice to narrow down the element you are attempting to interact with so that changes to the code don't instantly break your test. Also unless you start an xpath expression off with "//" or "xpath=" selenium Webdriver will not recognize it so even if your path never changed selenium Webdriver wouldn't be able to find it.
If I understand what you are trying to do then you can also remove lines 3-5 and replace them with the following,
element.click();
This will have selenium Webdriver zoom in on the chart provided by your link. I hope this helps
I noticed xpath cannot select anything within an svg tag. I managed to find elements using className or tagName selectors instead or you could even try cssSelectors but I am not sure about that one. Note that you can still use xpath to access parents of a node inside an svg using:
By.xpath("..");
Hope that will help.