org.openqa.selenium.ElementClickInterceptedException [duplicate] - selenium

This question already has answers here:
ElementClickInterceptedException: Message: element click intercepted: Element <label> is not clickable with Selenium and Python
(2 answers)
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable with Selenium and Python
(11 answers)
Closed 2 years ago.
Hi I am trying to write a piece of selenium code for the login page of: https://www.phptravels.net/admin.
I ab able to find the xpath for log in button but when the code is triggered I get this exception:
org.openqa.selenium.ElementClickInterceptedException: element click intercepted: Element ... is not clickable at point (640, 532). Other element would receive the click: ...
The code which I have written is:
public class pageObjectRepo {
WebDriver driver;
String mail="admin#phptravels.com";
String pass="demoadmin";
public pageObjectRepo(WebDriver driver)
{
this.driver=driver;
}
By email = By.xpath("(//*[#name='email'])[1]");
By pwd = By.xpath("(//*[#name='password'])[1]");
By loginbtn= By.xpath("//button[#type='submit']");
public void login() throws InterruptedException {
driver.findElement(email).sendKeys(mail);
Thread.sleep(1000);
driver.findElement(pwd).sendKeys(pass);
driver.manage().window().maximize();
Thread.sleep(5000);
driver.findElement(loginbtn).click();
}
login method is called in the actual test class.

I would try using the name locator instead of xpath which looks wrong.
By email = By.name("email]");
Try the same for password as well.

Do not use Thread. Sleep in order to wait for your web elements. Instead, use explicit wait. Moreover before clicking on the button check if the button is displayed and is enabled and then perform the click.

Related

Element is not clickable at point. Other element would receive the click [duplicate]

This question already has answers here:
Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
(9 answers)
Closed 3 years ago.
How can I bypass this and select the value I need?
behat #selenium2 #drupal7
When I select "male" from "profile_additional[field_gender][und]"
/**
* #When /^I check the "([^"]*)" radio button$/
*/
public function iCheckTheRadioButton($labelText)
{
foreach ($this->getMainContext()->getSession()->getPage()->findAll('css', 'label') as $label) {
if ($labelText === $label->getText() && $label->has('css', 'input[type="radio"]')) {
$this->getMainContext()->fillField($label->find('css', 'input[type="radio"]')->getAttribute('name'), $label->find('css', 'input[type="radio"]')->getAttribute('value'));
return;
}
}
throw new \Exception('Radio button not found');
}
Drupal\DrupalExtension\Context\MinkContext::selectOption()
unknown error: Element is not clickable at point (547, 470). Other
element would receive the click: ...
(Session info: chrome=74.0.3729.131)
(Driver info: chromedriver=2.43.600210 (68dcf5eebde37173d4027fa8635e332711d2874a),platform=Windows NT
10.0.17763 x86_64) (WebDriver\Exception\UnknownError)
The element you are trying to interact with is hidden beneath some other element. You can try using Actions to first move to your element, then try to interact with it. Now I am not an expert in PHP and I think this is the language you are using, the action should look something like this:
$action = new WebDriverActions($this->driver);
$action->moveToElement($element)->click()->perform();
If you know what element is causing this behaviour, then you can also try waiting for it to be gone, usually done via waiting for style attribute to contain none as in display:none
Better to use scroll to web element using javascript executor
JavascriptExecutor jse = (javascriptExecutor)driver;
jse.executeScript("arguments[0].scrollIntoView();"element)
This will resolve your issue

WebDriverException Element is not clickable in Selenium [duplicate]

This question already has answers here:
Element MyElement is not clickable at point (x, y)... Other element would receive the click
(5 answers)
Closed 4 years ago.
Here is the error message:
org.openqa.selenium.WebDriverException: unknown error: Element <div class="col-md-2 col-sm-2 hidden-xs days" id="lblday3">...</div> is not clickable at point (799, 308). Other element would receive the click: <div class="modal-body text-center">...</div>
(Session info: chrome=69.0.3497.100)
Hi everyone, the above exception was thrown in my ThankYou page in my project. I've tried to change the wait time but it also doesn't work. Below is the method I used.
public void Clickthankyou() throws InterruptedException
{
if(driver.findElement(By.xpath("//*[#id='id_appoint']/h2")).isDisplayed())
{
WebDriverWait wait = new WebDriverWait(driver, 6);
WebElement elem =wait.until(ExpectedConditions.elementToBeClickable(Dateselect));
if(elem.isDisplayed())
{
elem.click();
}
Thread.sleep(2000);
driver.findElement(Clickbook).click();
}
else
{
driver.navigate().back();
}
The basic reason of this exception is due to ViewPort of Browser window which is seen by the user.
You need to scroll to specific element then click on it.
Key thing is element is not visible so not eligible for clicking.
ok use this code for do the fix using JavascriptExecutor ,
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeAsyncScript('arguments[0].scrollIntoView(true)', driver.findElement(By.xpath("//*[#id='id_appoint']/h2")))
js.executeAsyncScript('window.scrollBy(0,-150)')
or you can also do same using Actions class.
new Actions(driver).moveToElement(driver.findElement(By.xpath("//*[#id='id_appoint']/h2"))).click().perform();
Possible duplicate of Debugging "Element is not clickable at point" error

Invalid selector exception for clicking an element using Selenium with Cucumber for W3Schools site

I am trying with the following Selenium Code using Cucumber for W3Schools site. When I click on "Try it yourself" button then it navigates to another page opening different window and the window control also goes to the new window opened. So,In the new window opened, if i click the run button, it throws an exception:
invalid Selector
code:
//This clicks on the Try it yourself button
#FindBy(how=How.XPATH,using="//*[#id=\"main\"]/div[4]/p/a")
private WebElement TryItYourself;
public void TryItYourSelfClick()
{
TryItYourself.click();
}
//Now,a new window opens up where I want to click on Run Button
#FindBy(how=How.LINK_TEXT,using="Run >>")
private WebElement RunButton;
public void RunClick()
{
RunButton.click();
}
Calling Run Method
#Then("^a new window should appear$")
public void a_new_window_should_appear() {
System.out.println("Run button before Clicking");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
obj1.RunClick();
System.out.println("Run after clicking");
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
Set <String> handle=driver.getWindowHandles();
String firstWinHandle=driver.getWindowHandle();
String WinHandle=handle.iterator().next();
if(WinHandle!=firstWinHandle)
{
driver.switchTo().window(WinHandle);
System.out.println("Working for new window opened");
}
}
why this invalid selector exception is coming?
HTML code:
<div class="w3-bar w3-light-grey" style="border-top:1px solid #f1f1f1;overflow:auto">
<a id="tryhome" href="https://www.w3schools.com" target="_blank" title="w3schools.com Home" class="w3-button w3-bar-item topnav-icons fa fa-home" style="font-size:28px;color:#999999;margin-top:-2px"></a>
<button class="w3-button w3-bar-item w3-green w3-hover-white w3-hover-text-green" onclick="submitTryit(1)">Run »</button>
<span class="w3-right w3-hide-medium w3-hide-small" style="padding:8px 8px 8px 8px;display:block"></span>
<span class="w3-right w3-hide-small" style="padding:8px 0;display:block;float:right;"><span id="framesize">Result Size: <span>433 x 439</span></span></span>
</div>
I'm not familiar with cucumber, but does it have an option to use cssSelector?
I looked at the button and found
body .trytopnav button
as a valid selector.
This error message...
invalid Selector Exception
...implies that the how=How.LINK_TEXT,using="Run >>" was not a valid selector.
The main issue is the element is not a LINK_TEXT but a <button> tag with text as Run ».
Solution
Change the Locator Strategy as follows:
#FindBy(how=How.XPATH,using="//button[contains(.,'Run »')]")
//or
#FindBy(how=How.XPATH,using="//button[contains(.,'Run')]")
private WebElement RunButton;
look here https://www.seleniumhq.org/exceptions/invalid_selector_exception.jsp we need to avoid using >> as possible, so try to use another locator by avoiding these

How to find element in frame in Selenium

I used below code for finding the element in the frame but I got the error
kindly explain by this framebyinedex, framebystring, framebywebelement:
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
public class Framebyindex
{
public static void main(String[] args)
{
WebDriver f1=new FirefoxDriver();
f1.get("http://spicareers.com/spicareers/");
f1.switchTo().frame(1);
f1.findElement(By.linkText(" .Net - Senior Developer ")).click();
}
}
The error is:
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":" .Net - Senior Developer "}
Before you have to switch to the frame:
driver.get("http://spicareers.com/spicareers/");
WebElement frame= driver.findElement(By.xpath("//frame[#name='JRAMPSMainFrame']"));
driver.switchTo().frame(frame);
and after you could try with:
WebElement myEl= driver.findElement(By.xpath("//*[contains(text(), ' .Net - Senior Developer ')]"));
myEl.click();
Finally, if you want to switch back:
driver.switchTo().defaultContent();
EDIT
The interested element is inside the iframe with name "JRAMPSMainFrame". If you inspect your html, you could notice this:
NoSuchElementException simply means that, the selenium did not detect a link with the text as you asked it.
I suggest you to work with use by.xpath to resolve it. To get the xpath of the element, take the below steps on your chrome, or firefox browser.
Right click on the element (here the link)
Click on inspect. It opens the inspect console (Elements tab) in your browser, and highlights the clicked element.
Right click on the element in the elements tab
Choose copy
Copy Xpath
In your code, replace By.linkText with By.xpath
Paste the value as an string into the xpath("you paste here")
Or simpler, watch this video
Seems like you have selected a wrong frame or the link text might contain more spaces.
Chrome developer tools is your best friend in this situation. Use it to find the element correctly and to identify the frame.
SELECT FRAME
Open the application in chrome.
Open developer tools
Click Console tab of developer tool
Select you frame from the drop down
In the above picture there is only one frame.
FIND ELEMENT
After selecting the frame, type $x("//a[normalize-space(.) = '.Net - Senior Developer']") to check your xpath.
$x("") is the function for checking xpath in browser.
Using the above mechanism find the frame and the element.
Cheers!
If you take a closer look at the HTML of http://spicareers.com/spicareers/ the WebElement with text as .Net - Senior Developer is within an <iframe> tag. So before accessing the intended WebElement we have to switch to the frame first either through the frame_name, frame_id or frame_index as follows:
System.setProperty("webdriver.chrome.driver", "C:\\Utility\\BrowserDrivers\\geckodriver.exe");
WebDriver driver = new FirefoxDriver();
driver.get("http://spicareers.com/spicareers/");
driver.switchTo().frame("JRAMPSMainFrame"); //using "frame_name"
WebElement elem = driver.findElement(By.xpath("//*[contains(text(), ' .Net - Senior Developer ')]"));
elem.click();
You can use this code, First enter into the frame using name locator and try to locate the career option then
Try this code, I have modified your code:
public class Framebyindex
{
public static void main(String[] args)
{
WebDriver f1=new FirefoxDriver();
f1.get("http://spicareers.com/spicareers/");
f1.switchTo().frame( f1.findElement(By.name("JRAMPSMainFrame")));
WebElement netCareer= f1.findElement(By.xpath("//*[contains(text(), ' .Net - Senior Developer ')]"));
netCareer.click();
}
}
By using:
https://github.com/nick318/FindElementInFrames
you can write following:
SearchByFramesFactory searchFactory = new SearchByFramesFactory(driver);
SearchByFrames searchInFrame = searchFactory.search(() -> driver.findElement(By.xpath("//*[contains(text(), ' .Net - Senior Developer ')]")));
searchInFrame.getElem().ifPresent(WebElement::click);

Selenium Web Driver

We are working on IE Automation using Selenium Web driver in C#.Net.
We are getting an exception in handling model popup window. We supposed to do below the action.
When we click on Link button it will open a popup window then we need switch to popup window selecting check box options and click on Submit button.
When clicking on Link button we are able to open the popup window. But here we are facing an issue like the child popup window is not loading with data and getting HTTP 500 Internal server Error.
I don't understand sometimes it was working properly with the same code but not all the times I am getting above issue when I am trying to perform above actions on child window.
is this any IE settings issue or my code issue even i ignored protected mode settings in IE settings.
I am trying with below code :
js.ExecuteScript("arguments[0].click();", driver.FindElement(By.XPath("//*[#id='ByNewNotes']")));
(or)
string jsWindowString = "NewWindow('pop_Type.jsp?Type=External&IuserId=NUVJK50'," + sessionId + ",'400','500');return false";
((IJavaScriptExecutor)driver).ExecuteScript(jsWindowString);
Could you please help on this issue.
Thanks in Advance.
Instead of using ExpectedConditions.ElementEx‌​ists use ExpectedConditions.elementToBeClickable or presenceOfElementLocated
WebDriverWait wait = new WebDriverWait(driver, 60);
WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.xpath(""//*[‌​#id='ByNewNotes']")));
element.click();
Either Try to use FluentWait. Create a by function of your element which you want to wait and pass it in below method
WebElement waitsss(WebDriver driver, By elementIdentifier){
Wait<WebDriver> wait =
new FluentWait<WebDriver>(driver).withTimeout(60, TimeUnit.SECONDS) .pollingEvery(1, TimeUnit.SECONDS).ignoring(NoSuchElementException.class);
return wait.until(new Function<WebDriver, WebElement>()
{
public WebElement apply(WebDriver driver) {
return driver.findElement(elementIdentifier);
}});
}
Hope it will help you :)
Have you tried
Thread.Sleep(2000);
We had the same issues and solved it with this simple way.