Technology:
Salesforce
Lightning
Selenium webdriver
Html:
Code Trials:
driver.findElement(By.xpath("//a[#title='Acq Prospects']"));
driver.findElement(By.linkText("Acq Prospect"));
Error:
Unable to find an element
You simply need to wait object to be visible. You can use the following code;
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.Until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//a[#title='Acq Prospects']")));
For more informations; link.
Note: Also ensure that there is no any element that overlay your object which you are trying to find.
To locate the desired element you need to induce WebDriverWait for the elementToBeClickable and you can use either of the following solutions:
cssSelector:
WebElement Acq_Prospects = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.slds-context-bar__label-action.dndItem[href='/lightning/o/Acq_Prospect__c/home']")));
xpath:
WebElement Acq_Prospects = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='slds-context-bar__label-action dndItem' and #href='/lightning/o/Acq_Prospect__c/home']")))
Related
I am very new to selenium and tried this and it didn't work. You can easily reproduce this by going to amazon site and search for hairclip and you will find this image in the search. Once this image is found, i want to go to next page but it is not happening.
System.setProperty("webdriver.chrome.driver", "C:\\software\\chromedriver_win32\\chromedriver.exe");
ChromeDriver Driver = new ChromeDriver();
Driver.get("http://www.amazon.com");
Driver.manage().window().maximize();
Driver.findElement(By.id("twotabsearchtextbox")).sendKeys("Hairclip");
Driver.findElementById("nav-search-submit-button").click();
By by = By.xpath("//img[contains(#src,'https://m.media-amazon.com/images/I/716AFuiNFoL._AC_UL320_.jpg')]");
WebDriverWait w = new WebDriverWait(Driver, 20);
WebElement element = w.until(ExpectedConditions.elementToBeClickable(by));
element.click();
Error as below
Expected condition failed: waiting for element to be clickable:
By.xpath:
//img[contains(#src,'https://m.media-amazon.com/images/I/716AFuiNFoL.AC_UL320.jpg')]
(tried for 20 second(s) with 500 milliseconds interval)
I appreciate your time for the reply and effort.
Looks like you wanna click on first image, in that case this xpath should work :
//img[#data-image-index='1']
try it like :
WebElement element = w.until(ExpectedConditions.elementToBeClickable(by.xpath("//img[#data-image-index='1']")));
element.click();
The XPath locator you are using //img[contains(#src,'https://m.media-amazon.com/images/I/716AFuiNFoL._AC_UL320_.jpg')] matches 4 elements on that page.
To click the element you want please use this locator:
(//img[contains(#src,'https://m.media-amazon.com/images/I/716AFuiNFoL._AC_UL320_.jpg')])[last()]
So the code line will be
By by = By.xpath("(//img[contains(#src,'https://m.media-amazon.com/images/I/716AFuiNFoL._AC_UL320_.jpg')])[last()]");
I have a project that I am working on with java and selenium.
the test work OK in UI mode.
However in headless mode I get this error
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562). Other element would receive the click: <div _ngcontent-yrc-c26="" class="footer">...</div>
how can I resolve this issue (working in UI mode). this is my code
WebDriver driver = getWebDriver();
WebElement element;
Thread.sleep(60000);
element = driver.findElement(By.xpath("//label[#formcontrolname='reportingDealPermission']"));
element.click();
why in selenium there is no operation to move to the element and break all layers.
this is the UI.
this is working in UI mode not working in headless mode, made sleep for 6 minutes and not resolved so this is not time issue
This error message...
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562). Other element would receive the click: <div _ngcontent-yrc-c26="" class="footer">...</div>
...implies that the click on the desired element was intercepted by some other element.
Clicking an element
Ideally, while invoking click() on any element you need to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label[formcontrolname=reportingDealPermission][ng-reflect-name=reportingDealPermission]"))).click();
xpath:
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission' and #ng-reflect-name='reportingDealPermission']"))).click();
Update
After changing to headless if it still doesn't works and still get exception there still a couple of other measures to consider as follows:
Chrome browser in Headless mode doesn't opens in maximized mode. So you have to use either of the following commands/arguments to maximize the headless browser Viewport:
Adding the argument start-maximized
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("start-maximized");
WebDriver driver = new ChromeDriver(options);
Adding the argument --window-size
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
options.addArguments("--window-size=1400,600");
WebDriver driver = new ChromeDriver(options);
Using setSize()
ChromeOptions options = new ChromeOptions();
options.addArguments("--headless");
WebDriver driver = new ChromeDriver(options);
driver.manage().window().setSize(new Dimension(1440, 900));
You can find a detailed discussion in Not able to maximize Chrome Window in headless mode
Additionally, you can also wait for the intercept element to be invisible using the ExpectedConditions invisibilityOfElementLocated before attempting the click() as follows:
cssSelector:
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.invisibilityOfElementLocated(By.cssSelector("div.footer")));
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.cssSelector("label[formcontrolname=reportingDealPermission][ng-reflect-name=reportingDealPermission]"))).click();
xpath:
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.invisibilityOfElementLocated(By.xpath("//div[#class='footer']")));
new WebDriverWait(getWebDriver(), 10).until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission' and #ng-reflect-name='reportingDealPermission']"))).click();
References
You can find a couple of related relevant discussions in:
Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
Element MyElement is not clickable at point (x, y)… Other element would receive the click
Try adding an explicit wait
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission']"))).click();
and if this doesn't work then try using the JS Executor
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission']")));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
None of the above answers worked for me. Try using action class as follows:
WebElement element = driver.findElement(By.xpath("//div[#class='footer']"));
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perform();
For this issue:
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element <label _ngcontent-yrc-c26="" formcontrolname="reportingDealPermission" nz-checkbox="" class="ant-checkbox-wrapper ng-untouched ng-pristine ng-valid" ng-reflect-name="reportingDealPermission">...</label> is not clickable at point (161, 562).
Another element receives the click:
Answer is to explicitly wait with javascript executor. This combination is working for me:
WebDriverWait wait = new WebDriverWait(driver, 10);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission']")));
((JavascriptExecutor)driver).executeScript("arguments[0].click();", element);
WebDriverWait wait = new WebDriverWait(driver, 10); ---> has deprecated and it gives an error. Please use below instead:
WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//label[#formcontrolname='reportingDealPermission']"))).click();
Ensure to import relevant items for the WebDriverWait and ExpectedConditions.
In my case "JavaScript" works:
WebElement ele = driver.findElement(By.xpath("(//input[#name='btnK'])[2]"));
JavascriptExecutor jse = (JavascriptExecutor)driver;
jse.executeScript("arguments[0].click()", ele);
It was taken from:
http://makeseleniumeasy.com/2020/05/25/elementclickinterceptedexception-element-click-intercepted-not-clickable-at-point-other-element-would-receive-the-click/
Answer is worked for me.
Please check the below sreenshot for the my problem reference.
Below alert is comes in between the the my button and frame.
enter image description here
In my case, nothing worked. Only the THREAD.SLEEP() method worked!
When I click the link icon in ck editor initially it worked, but when I re-run the code, it's not clicking the link icon in the ck editor.
This is the command I used initially:
driver.findElement(By.xpath("//*[#id='cke_29']/span[1]")).click();
Use WebDriverWait to handle dynamic element.
WebDriverWait wait = new WebDriverWait(driver, 30);
wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//a[starts-with(#id,'cke_')][#class='cke_button cke_button__link cke_button_off']"))).click();
As #akshay-patil commented use the a tag. The reason is that the <a> tag is the link itself... not the span!
You should use:
driver.findElement(By.xpath("//*[#id='cke_29']")).click();
Hope this helps!
The desired element is a JavaScript enabled element so to click() on the element you have to induce WebDriverWait for the element to be clickable and you can use either of the following Locator Strategies:
Using CSS_SELECTOR:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("a.cke_button.cke_button__link.cke_button_off[id^='cke_'][title^='Link']>span.cke_button_icon.cke_button__link_icon"))).click();
Using XPATH:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//a[#class='cke_button cke_button__link cke_button_off' and starts-with(#id,'cke_')][starts-with(#title,'Link')]/span[#class='cke_button_icon cke_button__link_icon']"))).click();
I am using switching to an iframe using the below statements but on the final wait I get web element not found. Does anyone have any suggestions? I have trolled through google for about a day trying different techniques. None have worked so far
WebDriver driver = DriverFactory.getWebDriver()
WebDriverWait wait = new WebDriverWait(driver, 15)
driver.switchTo().defaultContent()
WebElement iframe = driver.findElement(By.cssSelector(".b-iframe__iframe"))
driver.switchTo().frame(iframe)
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector(
'fieldset.radio-switch-group')))
Screen shot of HTML below image
As per the HTML you have shared to locate the desired WebElement you have to:
Induce WebDriverWait for the desired frame to be available and switch to it.
Induce WebDriverWait for the desired element to be visible and you can use either of the following solutions:
Using cssSelector:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.cssSelector("iframe.b-iframe__iframe[src*='securetest']")));
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("fieldset.radio-switch-group#balance-type")));
Using xpath:
new WebDriverWait(driver, 10).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.xpath("//iframe[#class='b-iframe__iframe' and contains(#src,'securetest')]")));
WebElement element = new WebDriverWait(driver, 20).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//fieldset[#class='radio-switch-group' and #id='balance-type']")));
Here you can find a relevant discussion on Ways to deal with #document under iframe
My script is failing because of the following exception.
org.openqa.selenium.WebDriverException: unknown error: Element is not
clickable at point (355, 160)
While loading the page if the element appears in the background, selenium tries to click and fails. I have used webdriverwait. Out of 10 times it fails around 3 times minimum.
How can I avoid/handle this without using Thread.sleep();
You should wait until invisibility of element using invisibilityOfElementLocated as below :-
WebDriverWait wait = new WebDriverWait(driver, 10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.xpath('xpath of please wait loading...')));
After this you could perform click on target element
Hope it will work..:)
Use explicit wait
WebDriver driver = new FirefoxDriver();
driver.get("http://somedomain/url_that_delays_loading");
WebElement myElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id("myElement")));
// or (new WebDriverWait(driver, 10)).until(
// ExpectedConditions.visibilityOfElementLocated(By.id("myElement")));
myElement .click();