VBA - Web Scraping : Instruction migration from IE to EDGE using Selenium - vba

I am trying to migrate the web-scraping instructions from IE to EDGE using Selenium. I noticed that there are substantial differences, so when converting an application instruction into VBE, this is:
ieObj.Document.getElementsByClassName ("login-button bold"). Item.Click
which in IE works great, I couldn't find any matches with Edge -Selenium. The first obstacle consists in the fact that the "ClassName" in Selenium does not exist so it is not possible to instantiate it with the corresponding .FindElement.
Is there anyone who has already solved the problem? How can I do ? Thanks for everything.

This getElementsByClassName ("login-button bold") will not work, as it contains multiple spaces which means it is combination of 2 classes.
You will have to switch to CSS selector or XPath
However, If you are interested to use CSS selector :
You can try this :
getElementsByCss(".login-button.bold")
Code:
ieObj.Document.getElementsByCss (".login-button.bold"). Item.Click

Does the class of the element like this class="login-button bold"? If so, you can try with FindElementsByCss to find the element by the two class names.
Sample code:
driver.FindElementsByCss(".login-button.bold").Item(1).Click
Note: You can change the number in Item() according to your situation. It depends on the position of the element of the class names collection.

Related

Handling button tag in selenium webdriver

In Red bus app i am trying to click on search buses button,I tried in many ways like this
driver. find element(by. xpath("//button"(contains(text()='Search Buses')")).click();
still getting unable to locate the element anyone having solution for this.
Actually your attempted xpath syntax is incorrect. You should try as below :
driver.findElement(By.xpath("//button[contains(text(),'Search Buses')]")).click();
or
driver.findElement(By.xpath("//button[text()='Search Buses']")).click();
You can find it using By.id() as well which would be much faster than xpath as :
driver.findElement(By.id("search_btn")).click();
Follow these links to learn more about xpath
https://www.w3schools.com/xml/xpath_intro.asp
https://www.w3schools.com/xml/xpath_syntax.asp
https://www.w3schools.com/xml/xpath_axes.asp

When invoking js.exec in Geb/Spock, the exec method is flagged as 'null'

I am creating a suite of tests (using Geb/Spock) for a web site. In one of them, the element I want to access is on the top of the page, so, to make sure that is visible, I want to scroll to the top of the page.
The command I am using is:
browser.js.exec('window.scrollTo(0, 0);')
or variations of it like
js.exec('window.scrollTo(0, 0);')
or other alternative like:
js.exec('window.scrollBy(0, -250);')
None of them makes the page scroll up, and when executing I get the following error (it is the only error, no other feedback). The error message using the other options listed above is identical (other than the command itself):
Condition not satisfied:
browser.js.exec('window.scrollTo(0, 0);')
| | |
| | null
| geb.js.JavascriptInterface#4019094f
geb.Browser#3dcac33e
at UserCreatesCompany.Go to Home Page and click on the log to
GitHub button as user User1(UserCreatesCompany.groovy:170)
I can not interpret the message that 'exec' is null. What exactly it means?
To make things more interesting, at the end of this script I am running the following cleanup procedure
js.exec('window.scrollTo(0, document.body.scrollHeight);')
DeleteButton.click()
$("button",'data-automation-id':"button-modal-yes").click()
}
and that works well: the page scrolls down. So, does not seem a problem about some missing library.
Any suggestion of what I may be doing wrong?
The version of the different components I am using is:
groovyVersion = '2.5.4'
gebVersion = '2.3'
seleniumVersion = '3.141.59'
chromeDriverVersion = '2.45'
First of all, you should not need to ever manually scroll the page to make elements visible - Selenium WebDriver which is underpinning Geb will do that for you automatically as soon as you start interacting (clicking, setting value, etc) with content.
Secondly, the failure you are getting is a failed assertion coming from a statement in an automatically asserted (then: or expect:) Spock block. It feels to me that you don't understand a concept which is core to Spock and therefore you should read about it in the manual first. It should make the failure you're getting clearer.
Thanks for the answer. Clearly: I was not fully aware of the different constrains the different blocks impose on what is executable or not. The manual is pretty clear once you have stumbled!
I am intrigued by your first assertion pointing that Selenium WebDriver will move to the element as soon as I interact with it. That was my understanding but it was not working. I made sure the element in question had a unique identifier, but still, it was not able to found it if the element had to be found by scrolling up. On the other hand it worked smoothly when locating the element WebDriver scrolled the page down.
Thanks again for the explanation. I have learn something new today!

scroll until the element is in view using Selenium2Library Keyword

I am using Robot Framework for my web application automation execution.I had found one such solution using Selenium Web-driver.
scroll until the element is in view using Selenium Webdriver
But I wanted to accomplish this using Robotframewrok-Selenium2Library.
Please suggest such keyword if any.
Thanks.
Finally I got the solution to my query. I have to download the ExtendedSelenium2Library from : Github_Page
then I installed it and it is working fine now.
Thanks.
ExtendedSelenium2Library solved the problem of scrolling down and selecting an element. I used the keyword 'Scroll Element Into View' for my application. However the ExtendedSelenium2Library will not work with the higher versions of the selenium2library.
Below is my 'pip freeze' command output which is working
robotframework==3.0.2
robotframework-extendedselenium2library==0.9.1
robotframework-selenium2library==1.8.0
robotframework-seleniumlibrary==2.9.2
selenium==3.8.0
urllib3==1.22
I was stuck at similar blockade and i could resolve as below:
Hope this might be of little help!
Use ExtendedSelenium2Library Library...
Example:
***Settings***
Library ExtendedSelenium2Library
*** Keywords ****
Add Your Methods
#Execute Javascript window.scrollTo(0,200);
Scroll Element Into View ${YourElement}
Wait Until Element is visible ${YourElement} timeout=5s
Set Focus To Element ${YourElement}
Click Element ${YourElement}

geb jquery.mouseover() not working

The geb documentation shows that it has built in jQuery support. Im interested in one particular method called mouseover. However when I try to use the mouseover function I get a warning saying, "Cannot resolve symbol 'mouseover'". This happens even when I'm using the code in their example. What am I missing?
This might not directly answer your question. But if you are trying to mimic mouse over action in Geb, you could also use
interact {
moveToElement(element)
}
http://www.gebish.org/manual/current/#interact-closures

selenium webdriver sendkeys issue on IE - frame moves/shifts

I am using webdriver with IE 9.
When I exceute a "sendkeys" on my webelement the content of the relevant frame moves/shifts upwards.
I debugged my code and the strange behaviour occurs exactly in that moment when this line is executed:
searchTerm.sendKeys(searchString);
"searchTerm" is a Webelement, which is created by the PageFactory in that class. In my case it is a "textbox".
Although it is possible to write text into my textbox, I am struggling with that strange behaviour and would like to get rid of this. The problem is that the affected frame move above other existing frame and elements...
I dont have this problem when using firefox...
Any Ideas?
Thanks in advance and best regards,
Thomas
If you're referencing to that it scrolls the content of a frame strangely, then that's something you'll have to live with. WebDriver had (and sometimes still has) serious trouble with interacting with elements when it had to scroll to them, that's why there's some aggressive scrolling involved. It should be harmless since it doesn't actually change anything.
If it really changes the page layout, then that's a problem which should be closely examined. File a bug at http://code.google.com/p/selenium/issues/entry or post some relevant testcase here.