selenium-rc

How to select any random value from a dropdown?

孤街浪徒 提交于 2019-12-04 04:52:31
问题 I am working on selenium using Java. In my application I want to select any random value from the dropdown. Please tell how is it possible? 回答1: Well, first get the total number of items in the dropdown. Then generate a random number between 0 and dropdown items count. Then select that number as index to set your dropdown item 回答2: Use getSelectOptions to get an array of options of the select box. Then generate a random integer between 0 (inclusive) and the length of the array (exclusive).

How to run Selenium Java tests with TestNG programmatically?

不羁岁月 提交于 2019-12-04 04:39:30
I am using Selenium RC with Java using TestNG as Test Framework. I'm using Eclipse as IDE. I want to invoke TestNG from my own program very easily. How can I do that? TheStijn gives a few good directions, although TestMethodWorker() is internal so you shouldn't use it. Based on the question, I'm not even sure the original poster is trying to launch TestNG in a separate process, so the API documentation might be what you're looking for: http://testng.org/doc/documentation-main.html#running-testng-programmatically My following code in java works nicely: @Test public void

Using Selenium for selecting an option on a select with optgroup

拥有回忆 提交于 2019-12-04 03:59:07
I'm trying to select a value in a select element. I'm using Selenium RC (Java) to run the test cases. I understand that the code for selecting a value is given by: selenium.select("locator", "value=REQUIRED VALUE") I'm unable to select the desired value with the above code. I think it might be something to do with optgroup in the select source code. I do not get any exceptions, the command executes fine but looking at the page the required value is not selected. Also, I cant use ids (instead of value) because there arent any. Here is the source code of the selector: <select> <optgroup label=

What to use instead of CONTAINS() in CSS3

删除回忆录丶 提交于 2019-12-04 02:01:01
Question about automation. I use Selenium RC. I upgraded my FF to 3.6.18 and it seems that it can't find any locators which have "contains()" inside I've read alot of forums. It's a known problem, but I did not find any solution. So what to use instead of contains() now? The only functionality in CSS which is similar to contains() is: element[attribute*="substring"] It is helpful when you need to check some substring which contains in the attribute. You can use jQuery :contains(text) <script src="https://code.jquery.com/jquery-1.10.2.js"></script> <script> $( "div:contains('foo')" ).css( "text

Need to compare 2 html documents using Java & selenium

随声附和 提交于 2019-12-03 22:55:38
问题 I have to check the differences between two html pages: One is an old version and the other is the updated page. I need Selenium to get the source of the two pages and then compare them to check the differences. How can I achieve this using Java & Selenium? Below is the flow I have: Go to the old page using Selenium Collect all the data for the old web page Convert the data to a standard format (XML probably); create a class to do this Save the data to a file Go to the new page using Selenium

Selenium click right on mouse or press option key form keyboard

妖精的绣舞 提交于 2019-12-03 21:54:17
Using selenium how can I click on the right click of mouse or press on the option key from keyboard(This key is usually available between right ALT and CTRL key) If you are trying to open the context menu, there is a selenium.contextMenu(locator) . This is the menu that opens up when you right click or press that option key. This example shows you how to open a page element in a new tab from context menu. The page used for example is seleniumhq.org. This code will right click on the logo link and open the page in a new tab selenium.contextMenu(link=Selenium); //In the below line of code "t" is

Selenium get dynamic id from xpath

半腔热情 提交于 2019-12-03 21:13:09
Is there a way in Selenium RC to get the id from the xpath? If I have the xpath /html/body/div/div//input I want to get the id of all the nodes associated to the xpath You can get that by running a javascript, using this.browserbot.findElement('/html/body/div/div//input') : Of course, this depends on the source language, but it would be something like this (in perl, untested): #first count the number of inputs with ids my $count = $selObj->get_xpath_count('/html/body/div/div//input[@id]'); #build a javascript that iterates through the inputs and saves their IDs my $javascript; $javascript .=

Selenium: delete contents from a textbox

一曲冷凌霜 提交于 2019-12-03 17:13:22
问题 Through selenium. how to delete contents from textbox. I have to delete the last 2 characters from text box using selenium command. Ex.ABCD to AB. 回答1: Try this - selenium.type("text_box_object", "ABCD"); selenium.typeKeys("text_box_object", "\b"); selenium.typeKeys("text_box_object", "\b"); 回答2: The keyPress event of selenium can be helpful: selenium.sendKeys("text1", "ABCD"); selenium.sendKeys("text1", "\b"); selenium.sendKeys("text1", "\b"); This will Click Backspace key twice. 回答3: Read

Simulate TAB keypress event in Selenium RC

为君一笑 提交于 2019-12-03 15:41:39
问题 I need to simulate a tab keypress in Selenium RC, using the Java API. I do this after having entered some text using: selenium.type(input, "mytext"); I've tried 3 alternatives to get the tab working: selenium.keyPress(input, "\\9"); and: selenium.focus(input); selenium.keyPressNative("09"); and even: selenium.getEval("var evt = window.document.createEvent('KeyboardEvent');evt.initKeyEvent ('keypress', true, true, window,0, 0, 0, 0,0, 9,0);window.document.getElementsByTagName('input')[2]

selenium, how can I select new window

折月煮酒 提交于 2019-12-03 14:39:32
I run my selenium rc test in Eclipse with TestNG. I have a link which tries to open a new browser page. How can I select this new page to operate in? I use this code: selenium.selectWindow("name=NewPage"); however it says page not found. I also try to define page ids or titles with this code: String[] wins = selenium.getAllWindowIds(); for (String s : wins) System.out.println("win: " + s); It does not define my new opened window: win: MainPage win: If use selenium.getAllWindowNames() I get win: selenium_main_app_window win: selenium_blank65815 . I write this code selenium.selectWindow("name