Selenium for VBA - element not found error - vba

I have been using a code since long time , but recently there is a new banner up which is hiding the element that I am trying to click.
Attaching the snapshot of error. The only help I need is I need to click the hidden element( if the browser window is maximized the element is visible).
.
Please help me.

If what you have said is true then you can use the following to maximize the window before clicking:
driver.Window.Maximize
Other options include:
1) Removing the banner
2) Scrolling the element into view
Can't write anything decent for those last two as your code is an image and I don't have a full URL to test with. You also haven't included the relevant HTML.

The "div.container-fluid" element is blocking the button you are trying to click.
You could try some of the following (as being shown here Element MyElement is not clickable at point (x, y)... Other element would receive the click):
prolong the wait before the click
use javascript executor

Related

Trouble getting an element to be clicked using Selenium

I am trying to go to the below URL
https://twitter.com/explore
Enter HBO Max in the text box which I locate using
By.cssSelector("input[placeholder='Search Twitter']")
and then I want to select the HBO Max option that appears in the dropdown. My locator for the element to be selected is
By.xpath("//div[#role='option']//li/div/div[2]")
Sometimes the element gets clicked and I go to the new page, sometimes not. I have in my framework waited for the element to be clickable using WebDriverWait. The element is both visible and enabled because I print these values before I click the element.
Additional debugging steps performed -
Click using JavaScript seems to have the same behavior.
I believe I am using the right locator because the mouse event gets generated for this element.
Thread.Sleep seems to work suggesting that perhaps a timing issue
Any inputs would be great.
try:
myElem = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.ID, 'ID')))
print("Page is ready!")
except TimeoutException:
print("Loading took too much time!")
Try this !
what it does : It wait until the specific element of the site is loaded. If it takes more time than specified will just give you an output as "loading took too.........."
You can modify the time required to wait.

Selenium WebDriver Explicit Wait intermittently not working

Good day everyone,
I need your help in this method. I have a web page that will have a loading screen UI when the page loads, and I'm waiting for it to finish before clicking a button.
Here is my code:
#Step("Go to Audit Inquiry Screen")
public void launchAuditInquiry(){
WebDriver webDriver = Driver.webDriver;
WebDriverWait wait = new WebDriverWait(webDriver, 10);
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("loading-container")));
WebElement auditInquiryBtn = webDriver.findElement(By.linkText("Audit Inquiry"));
auditInquiryBtn.click();
}
My issue is sometimes, this code works fine. It will wait for the loading ui div to be invisible before clicking the button. But sometimes it will produce this error:
Error Message: org.openqa.selenium.WebDriverException: unknown error: Element <a class="module-item" href="/audit/inquiry">...</a> is not clickable at point (822, 436). Other element would receive the click: <div class="loading-container" style="display: flex; opacity: 0.899842;">...</div>
I tried adding another explicit wait before clicking the button to be sure, like this:
wait.until(ExpectedConditions.invisibilityOfElementLocated(By.className("loading-container")));
WebElement auditInquiryBtn = webDriver.findElement(By.linkText("Audit Inquiry"));
wait.until(ExpectedConditions.elementToBeClickable(By.linkText("Audit Inquiry")));
auditInquiryBtn.click();
But it will sometime produce the same error above, and sometimes it will work fine.
I'm just confused on how to remediate the issue.
Thank you guys for the comments, especially this: Selenium Web Driver & Java. Element is not clickable at point (36, 72). Other element would receive the click
It was helpful, but some items there, I have already tried, but did not work as well. The part that I did check was one item there and also a comment here also which is to force a click:
new Actions(driver).moveToElement(auditInquiryBtn).click().perform();
But I'm having second thoughts on this because, a scenario may happen that when the loading container div is still overlaying the page, then I forced clicked the submit button, it will also produce another loading container div, and I'm not sure what will happen if there are two loading container div present.
Now, my solution on this is to adjust the sleep timer of the wait function:
WebDriverWait wait = new WebDriverWait(webDriver, 10, 2500L);
It now works because it gives the loader div time to generate before the first check of wait. 500 ms was a bit fast for the loader to render. I'm still testing this but if it didn't work, I might do the solution above.
Thanks again.
First thing to try is remove the invisibilityOfElementLocated wait and just use elementToBeClickable. I've never really trusted what Selenium considered "visible" and "invisible".
I've had issues in the past where the element to click on was completely off screen, so Selenium automatically scrolled until it was considered in the viewport. But because of a floating footer, it didn't scroll enough and was still behind the footer so could not be clicked on. It was still considered "visible" because it was in the viewport.
But, if you're sure, you can try forcing a click at a coordinate instead of an element.
new Actions(driver).moveToElement(auditInquiryBtn).click().perform();

How to send a click to hidden button?

I have a simple submit button on a page that I need to send a click for it but this button is at the bottom of the page and does not appear unless a user uses the browser vertical scroll bar to reach it !!
so when I use this C# code I get error element is not visible so how I can solve this problem ?
driver.FindElement(By.Id("submit")).Click();
You could scroll down using javascript. Something like this should do the work.
((JavascriptExecutor) driver).executeScript("window.scrollTo(0, document.body.scrollHeight)");
Selenium Webdriver implicitly scroll to the element, if it is visible. You can wait for the visibility of the element and then perform the click operation. In Java, we can wait for the visibility using following code:
WebDriverWait wait = new WebDriverWait(driver, 60);
wait.until(ExpectedConditions.visibilityOfElementLocated(driver.findElement(By.id("submit"))));
In the above code, Webdriver will wait for 60 seconds, for the required element to become visible. If within 60 seconds, the element does not appear, then it will fail with timeout error. Once, the required element is visible, it can be clicked.
If it's not visible by you, it is not render by the browser used through your selenium driver.
I recommend you to simulate a scrolling to ensure your item will be visible, or do a simulation on a bigger resolution ?
Eventually you can consider switch to an headless driver...
I found the problem there are two elements in the page with id="submit" !! I used Name and now it work fine, thank to all.

Clicking label element that unfortunately contains a link

I'm running into an issue where I'm attempting to click on a checkbox. The app is written in AngularJS.
The checkbox can not be clicked, as technically the element is not visible. Using 'visible: false' does not help to get this box checked. I have also tried to use element.set(true)
The checkbox is within a label element that happens to also contain hyperlinks. Since Capybara/Selenium clicks on the middle of an element by default, I end up opening the hyperlink instead of marking the checkbox. Clicking within anywhere in the label (outside of the hyperlinks) checks the box successfully.
How can I achieve this?
I would recommend using JavascriptExecutor to click element. In case element is technically not visible Webdriver will not allow you to click it using API, as it tries to simulate real user actions. Nevertheless you have the option to execute JS directly, which doesn't really care.
This answer will help you with the code part:
https://stackoverflow.com/a/19934852/2998104
You would need to change ending slightly to:
JavascriptExecutor js = (JavascriptExecutor) driver;
WebElement element = driver.findElement(By.xpath("exact_locator_of_checkbox"));
js.executeScript("arguments[0].click()",element);
Of course no need to use only xpath, but anything that help you point to the checkbox directly.
Took me a little while but I figured out that I can avoid the Capybara API and use WebDriver's ActionBuilder.
def agree
source = find('label.terms-label').native
actionbuilder = page.driver.browser.action
actionbuilder.move_to(source, 0, 0).click.perform
end
By default, the Capybara API (as well as other native Selenium methods) will click in the center of the element. This will avoid that and will find the element and click it at (0, 0) coordinates.
As of Capybara 3.0.0, you can specify an offset when you call click on an element. So if you want to click the top-left corner of the element box, you'd say:
find('label.terms-label').click(x: 0, y: 0)
(Note, you must specify :x and :y if you specify either)
API Docs
Relevant commit

How to wait until page freezes in Selenium WebDriver?

We have got following logic on frontend - so when new page is loaded, screen is auto scrolling to specific section and I have a script which clicks on the specific element at that time. Hence, while this movement is occurring following error is appearing due to the fact that selenium is clicking on wrong element:
"Element is not clickable at point (x, y). Other element would receive
the click..."
I have added plain sleep, but this solution is not a good one. So does any one know how to wait until page freezes - when auto scrolling is finished?
f you know what element you're scrolling to (the element that is at the top of browser viewport when you're done with scrolling) you can wait for the y property of a navigator representing that element to equal zero. Following is an example that you can paste into groovy console which goes to a page and then scrolls to an element by using it's id in the url (I know there is no waiting here nor the scrolling is animated but I just want to show how that property can be used to achieve want you want):
I am not familiar with protractor, so you will have to adjust the block syntax appropriately.
waitFor {
elementWeScrollTo.y == 0
}