VBA button not clicking - element not visible error - vba

I'm trying to click a button using a VBA Chrome driver via Selenium but I get an ElementNotVisibleError
The HTML code for the button is -
<button class="base-button" id="primary-button" classnames="primary-button" title="Continue">Continue</button>
I've tried to check the element exists and VBA returns TRUE for the following -
MyBrowser.IsElementPresent(Findby.ID("primary-button"))
but when I try to click the button using the following code, i get the error -
MyBrowser.FindElementById("primary-button").Click

To click on the element you can use either of the following locator strategies:
Using FindElementByCss:
MyBrowser.FindElementByCss("button.base-button#primary-button[title='Continue']").Click
Using FindElementByXPath:
MyBrowser.FindElementByXPath("//button[#class='base-button' and #id='primary-button'][#title='Continue' and text()='Continue']").Click

Related

Access to a pop-up in selenium

I do have the following code to click a Google button that open a pop-up and then it selects the second Item. It worked fine but now is failing, I guess that due to ID name changed. I do not remember how I Inpectioned the pop-up ID since it does not appears in the "Inpection" Chrome Window.
numOpiniones.click()
self.driver.find_element(By.XPATH,"//button[#data-value='Ordenar']").click()
sleep(random.uniform(1, 1.5))
self.driver.find_element(By.XPATH, "//li[#role='menuitemradio' and #data-index='1']").click()
"menuitemradio" does not exists anymore but I can not see that element in the inspector panel when is created/displayed.
enter image description here
You can use the following css path
driver.find_element(By.CSS_SELECTOR, '#hovercard > #action-menu > [data-index="1"]')

VBA selenium scroll windows to element point

In VBA I need to move in Selenium viewport to the element to be clickable. I tried code below ;
.Mouse.MoveTo(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a"),13,13) 'error Expeted = sign
.Actions.MoveToElement (.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a")) 'ineffective screen does not scroll down. Note: Windos is set to Maximize
the code is added but does not work, I could not add to the comment section
.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a").Click
.Actions.MoveToElement(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform
.Actions.MoveToElement(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform
.Actions.MoveByOffset(300, 300).Perform
.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a").Click
To move Selenium's focus to the element you can use either of the following lines of code:
.Actions.MoveToElement(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a")).Perform
or
.Actions.MoveToElement(.FindElementByXPath("//*[#id=""main-content""]/section[2]/ul/li[2]/div/a"), 13, 13).Perform

Find this element in this website using Selenium

I have used Selenium in VBA to get to this page and would like to click on the 'WIP Management' Button. However the code that I use says the element is not found. Could someone please help.
This is the part of the website with the inspect panel
This is my code that can't find the element.
If obj.IsElementPresent(By.XPath("//button[text()='WIP Management']")) Then
MsgBox "True"
Else
MsgBox "False"
End If
I can not see the button tag in HTML, try the below locator
//*[text()='WIP Management']
OR
//*[contains(text(),'WIP Management')]
OR
//*[normalize-space()='WIP Management']

selenium send key for xpath not working

I want make automation for this web site
in this web site 3 text box are here check image
1st text box x path is /html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]
here is my code
driver.findElement(By.xpath("/html[1]/body[1]/div[3]/div[1]/div[2]/div[1]/searchbar[1]/div[1]/div[1]/div[1]/div[1]/form[1]/div[1]/div[1]/div[1]/input[1]")).sendKeys("rio salon");
when I run this code I got this error
Exception in thread "main"
org.openqa.selenium.ElementNotInteractableException: Element is not reachable by keyboard
How can i fix it? I hope my xpath is correct.
The field has aria-hidden=true attribute, so you get ElementNotInteractableException. You need to click on the dropdown first to change the attribute to true
WebElement dropdown = driver.findElement(By.xpath("//*[#id='search-form']/div/div[1]/div/div[1]/span"));
dropdown.click();
WebElement textField = dropdown.findElement(By.xpath("./parent::div/following-sibling::input[contains(#class, 'ui-select-search')]"));
textField.sendKeys("rio salon");
You can click in an input field with a div or span tag, but you cannot type in the field. So, your XPath must be written with an input tag if you want to sendkeys or type in an input field. For example:
//input[contains(#placeholder,'Site')]

Checkbox does not get checked

Hi I am automating a webpage which contains multiple checkbox.
It clicks on a some checkbox and misses some checkbox.
This is my code.
Should I put a wait statement before the click to avoid this problem.
IWebElement ClickElement = Wait.Until((d) => webDriver.FindElement(By.Id(parameter1)));
ClickElement.Click();
Can you try making this change in your code -
In wait until function you are checking if the element exists by using findElement(By.Id(parameter1))
After finding the WebElement check if this is displayed by using isDisplayed() method with in the waitUntil function.
You can also check if it has already checked or not by using isSelected() method.