I am new at helium automation tool, I am trying to automate google login page
Link: https://www.google.com.bd/?gws_rd=cr,ssl&ei=zi5rVfScH4yfugTkv4EY
In this page I want helium to click the sign in button
I know the syntax can be as following
click("Sign in");
click(Button("OK"));
click(Point(200, 300));
click(ComboBox("File type").getTopLeft().withOffset(50, 0));
My question is how I can use the point and comboBox option for the above sign in button.
Thanks in advance.
Use click function:
from helium import *
click('login in')
write("your usrname", into="field name")#input field
write("your pwd", into="field name")#input field
click('login')
Sometimes you should verify bot check manully.
Related
I am new to WebDriver,and currently trying to write the code to click the button. The locator is not available so I have used Xpath,but it is not working as it should be. Kindly help me on this.
Button tag:
<button onclick="myFunction()">Try it</button>
My web drive code:
drive_url.findElement(By.xpath("html/body/button")).click();
Did you check your xpath in browser console. You can check xpath by writing $x("<your xpath>") in console. Try using "//button" instead of what you're using now.
You should be little careful writng the selector as well. Try to avoid flaky selector and make is as unique as possible.
By xpath = By.xpath("//button[contains(text(),'Try it')]");
drive_url.findElement(xpath ).click();
The above selector finds the button tag explicitly using text based search.
Try this:
WebElement btn = driver.findElement(By.tagName("button"));
String btnText= driver.findElement(By.tagName("button")).getText();
if(btnText.equals("Try it")){
btn.click;
}
When we use selenium command at that time command not find and attribute not get? See below command.
<table>
<tr><td>open</td><td>http://www.wikipedia.org/</td><td></td></tr>
<tr><td>verifyAttribute</td><td>css=input#searchInput</td><td>(Search Input)</td></tr>
<tr><td>assertAttribute</td><td>css=input#searchInput</td><td>(Search Input)</td></tr>
<tr><td>verifyAttribute</td><td>css=input#searchInput</td><td>language</td></tr>
<tr><td>verifyAttribute</td><td>xpath=//div[2]#class central-featured</td><td>central-featured</td></tr>
<tr><td>verifyAttribute</td><td>xpath=//div[2]#class central-featured</td><td>search1</td></tr>
<tr><td>assertAttribute</td><td>xpath=//div[2]#class central-featured</td><td>central-featured</td></tr>
</table>
I am using Selenium IDE 2.5.0 in Mozilla Firefox and Ubuntu.
Xpath //div[2]#class central-featured is invalid. Try changing it to //div[#class='central-featured']/#class if you mean to select a class.
You could also use assertElementPresent function instead of selecting attribute, if the whole point is to check that element exists, i.e.:
<tr><td>assertElementPresent</td><td>xpath=//div[#class='central-featured']</td><td></td></tr>
Much simpler that way.
Use xPaths in this case.
Use google chrome's built in developer tool for this
Place your cursor on the element
Press Ctrl+Shift+C
Click the Element
That clicked Element's code is highlighted in the short window on the bottom
Right-Click on highlighted code
Select Copy > Copy XPath
Here it is you have copied the xPath for that specific element. This is shown in the image:
Click to see how to copy xPath
The Xpath you have used in Invalid.
You can use xpath as follows and through this you can fins xpath of any object - just need to study the concept:
Here as we can see we want to search Google Search just by writing its xpath in console
So to find the Google Search button we have to write xpath like this
//span[#id='gbqfsa']
Once we hit enter it would bring
[ gbqfsa">Google Search ],
It shows that xpath for Google Search Button is correctly written
Now suppose we want to search Google Search button if we are just familiar that id attributes start with gbqfs
then we have to use function starts-with like this
//span[starts-with(#id,'gbqfs')]
and once when we hit enter on console it would reflect two button one is Google Searchand Second one is I’m Feeling Lucky
[
gbqfsa">Google Search
,
I'm Feeling Lucky
]
So to find out the Google Search uniquely we need to complete id attribute to gbqfsa
“//span[starts-with(#id,'gbqfsa')]
and hit to enter and now it would reflect only
[
Google Search
],
It proves that we have written right xpath for Google Search
In the same fashion we can use Contains function to find the Google Search button like this
here I have taken fsa from gbqfsa
//span[contains(#id,'fsa')]
hit enter and hopefully it will return
[
Google Search
],
if there are multiple attributes then we can use:
//span[contains(#id,'fsa') and contains(#class, 'xyz')] hit enter and hopefully it will return
Information Source: Sumit Mittal Blog
You can use CssSelector as below
webDriver.findElements(By.cssSelector("div.central-featured")) // for more than 1 elements with same class
webDriver.findElement(By.cssSelector("div.central-featured")) // for 1 element
I am testing a scenario for the site "https://www.freecrm.com/index.html"
login credentials [ john2013 / john2013 ]
Scenario :
1 open the site https://www.freecrm.com/index.html
2 login with valid credentials
3 click on the "New Contacts" link
4 Add new contacts
using Selenium ide i am able to login and click on the "New Contact" link , but when i am trying to do the same thing using Webdriver [ java] i am not able to click the "New Contact" link
the code i have written is given below
driver.findElement(By.name("username")).clear()
driver.findElement(By.name("username")).sendKeys("john2013");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("john2013");
driver.findElement(By.cssSelector("input[type=\"image\"]")).click();
The code up to the above is working fine but clicking the "New Contact" link
driver.findElement(By.xpath("//div[#class='noprint']/span[#class='headertext']/a[3]/")).click();
is not working though the same xpath is working in IDE.
i have tried with expected condition option , sleep but nothing is working.
can any one help me in this regard.
The problem is that your page uses a frameset. You should tell your webdriver which frame to use when it will search for your element. So try this:
driver.findElement(By.name("username")).clear()
driver.findElement(By.name("username")).sendKeys("john2013");
driver.findElement(By.name("password")).clear();
driver.findElement(By.name("password")).sendKeys("john2013");
driver.findElement(By.cssSelector("input[type=\"image\"]")).click();
//switch the driver to use one of the frames on your page. Potentially wait for a bit till the page is loaded
driver.switchTo().frame("mainpanel");
driver.findElement(By.xpath("//*[text()='New Contact']")).click();
Please change the xpath of link to
xpath=//a[contains(text(),'<whatevertext>')]
Incase if the same text link is already present in some part o the page we can proceed with occurences. Example if it is repeating second time:
xpath=(//a[contains(text(),'<whatevertext>')])[2]
If Nothing is working the best way is through java script executor.
First get the webelement of the link.
Then use the following code"
webelement=driver.findElement(by.xpath("=//a[contains(text(),'')]
"))
(JavaScriptExecutor)driver.executescript("argument[0].click();",webelement)
Actually Speaking //div[#class='noprint']/span[#class='headertext']/a[3]/ is absolute XPath.
as it ends with a[3] the position will vary always so it is advisable to use relative XPath/CSS
Suggested CSS:css=.noprint > .headertext > a.classname
Another Suggested CSS: css=.noprint > .headertext > a[attribute='value']
So we can use either of the above format.
In our application when I mouse over a menu item, drop down appears, where I want to select an item by clicking on it. The structure of the menu is as follows,
Main Menu
Admin Sub menu:
Manage Channels
Manage Users
In selenium webdriver, I tried to click directly on Manage Channels by giving the xpath, linktext, partial link text. But in options it says unable to locate element. I'm attaching a screen shot for reference
driver.findElement(By.linkText("Manage Channels")).click();
driver.findElement(By.xpath("//li/a[contains(., \"Manage Channels\")]")).click();
driver.findElement(By.partialLinkText("Manage Channels"));
Basically, you'll have to first move mouse to 'Menu item' drop-down and then move mouse to option which you want to select and then click on option.
For Ruby following is one line code:
driver.action.movet_to(el1).movet_to(el2).click.perform
I don't know about Java but you can apply above logic. I tried with following Java code, see if it works or modify it wherever required:
WebElement element1 = driver.findElement(By.linkText("Manage Channels"));
WebElement element2 = driver.findElement(By.xpath("//li/a[contains(., \"Manage Channels\")]"))
Actions action = new Actions(driver);
action.moveToElement(element1).moveToElement(element2).click().build().perform();
You can use following methods to hover your mouse on intended menu item:
el = driver.find_element(:id, "some_id")
driver.action.move_to(el).perform'
el = driver.find_element(:id, "some_id")
driver.action.move_to(el, 100, 100).perform
For more guidelines please refer this link : http://selenium.googlecode.com/svn/trunk/docs/api/rb/Selenium/WebDriver/ActionBuilder.html#move_to-instance_method
Hope this will help you !!!
Cheers...
I am using Moodle 2.3
I am trying to add help button to my self registration form in moodle. I am making changed in
/login/signup_form.php page.
I am using:
$mform->addHelpButton('country','country','moodle');
This creates a help icon on the page. But clicking on the icon it loads the help information on the same page. The pop up doesn't work. No JavaScript errors found in firebug.
Plz help
You need to on ajax/javascript setting from the admin.
Site administration > Appearance > AJAX and Javascript
You should also add an entry to lang/en/moodle.php
For example
In course/edit_form.php I added the following field
// Course Champion$mform->addElement('text', 'champion', 'Champion', get_string('champion'), 'size="256"');
// New field$mform->addHelpButton('champion','courseChampion');
// Field help$mform->setDefault('champion', 'Firstname Lastname');
Then in lang/en/moodle.php I added the help information for that field.
$string['courseChampion'] = 'Course Champion';
$string['courseChampion_help'] = 'Enter the firstname and lastname of the champion.';
In moodle.php under /root/lang/en, add the following string:
$string['country_help'] = 'Your text here';