Creating Custom Object in Salesforce Lightning using Selenium Webdriver - selenium

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

Related

window.stop() execution through selenium is not working

I am trying to read elements from the page using selenium but it seems the page is getting loaded infinitely. The element which I want to read is visible on the page (tried xpath and I was able to fetch the element). I tried the below code to execute the javascript command to stop the page load but for some reasons it is getting time out.
driver.executeScript("window.stop());
As #pcalkins suggested to use PageLoadStrategy, I used the "none" strategy in the chrome capabilities and it really did work. Below is the chrome capability property which I set.
"pageLoadStrategy" : none

Getting "Nosuch element Exception" in Selenium Though XPATH is correct. Not sure is this due to Shadow DOM. Please confirm

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

Selenium cssselector shows correct webelement but script always run exception no such element

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")));

can not find web element using webdriver?

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.

Selenium “Element is not clickable at point” error in Firefox but working in Chrome

In Selenium I am trying to locate an element.
But getting the below error:
org.openqa.selenium.WebDriverException: Element is not clickable at point (1009.25, 448.183349609375). Other element would receive the click: <rect data-sdf-index="7" height="390" width="420" class="aw-relations-noeditable-area"></rect> (WARNING: The server did not provide any stacktrace information)
Command duration or timeout: 12 milliseconds
Getting this error in firefox. But its working successfully in Chrome browser.
Is anyone having solution for it?
I already tried help from this post:-Selenium "Element is not clickable at point" error in Firefox but not able to get the result.
I have written below code:
public void createPortOnSelectedNode( String nodeName ) {
ISingleLocator m_nodeContainer = m_nodePage.getNodeContainer();
WebElement node = m_nodePage.getNode( m_nodeContainer, nodeName ).getElement();
Actions action = new Actions(DefaultDriver.getWebDriver());
action.moveToElement(node, 40, 0);
action.click();
action.perform();
}
Hi the above error comes under such scenario where Your webdriver script performs the action but the element on which you want to do operation is not properly loaded inside the DOM i.e its position is not fixed inside the DOM tree (also note selenium is able to perform its action because element is available inside the DOM hence webdriver only looks for the presence of element inside the DOM and not its position inside the DOM)
So how to overcome this issue
1.Give time to DOM to properly give positions to its element.
and that can be achieved by :
1.Instead of performing operation's directly at the target area try to do some extra/false
activity with webdriver which will give time for DOM to position all of his elements
2.apply Thread.sleep().
3. also if you are running your test in smaller window size then set the size to maximum it
will also help
i have not included any code cause the link that you have refer in the question contains ample amount of work regarding that so i decided to make everybody underrated why this error occurs. thanks hope this helps
Have you tried to click directly using Javascript? In python I use
driver.execute_script("arguments[0].click();", elt)
In Java it should look like executeScript instead...