Menu
  • HOME
  • TAGS

How to write xpath in selenium webdriver for below HTML expressions?

Tag: selenium

I wrote xpath for below HTML code i.e. displayed below

1.   //a[@text()='Life Insurance']
2.  //span[@text()='Apply now']

But I got element not found exception. If I used Absolute xpath processor then It's working and I wrote own xpath then it thrown exception. Please tell me how to write it.

Below are the HTML code for which I need xpath.

1.<a class="mainlink" href="https://leads.hdfcbank.com/applications/webforms/apply/HDFC_Life_Click2Protect/index.aspx?promocode=P4_hp_AppNow_LI" target="" rel="nofollow width=375 height=213">Life Insurance</a> 

2." <div class="menutext"> <span class="mainlink">Apply now</span> <img class="pointer" alt="Pointer" src="/assets/images/nav_pointer.png" style="display: none;"> </div> "

Best How To :

Try these For 1

//a[text()='Life Insurance']

For 2

//span[text()='Apply now']

WebDriver can't get dropdown menu element (Java)

java,selenium,webdriver,junit4

Your ID is dynamic, so you can't use it. Select will not work in your case, you just need to use two clicks WebElement dropdown = driver.findElement(By.xpath("//div[@class='select-pad-wrapper AttributePlugin']/input")); dropdown.click(); WebElement element = driver.findElement(By.xpath("//div[@class='select-pad-wrapper AttributePlugin']/div/ul/li[text()='Image']")); element.click(); ...

How to Find class inside in
, using Selenium WebDriver

selenium,webdriver

This issue Compound class names not permitted occurs because the class name has multiple words you can resolve this by using the below xpath driver.findElement(By.xpath("//article/div[contains(@class,'one-fourth-percent')]") Hope this helps you.Kindly get back if you have any queries...

Selenium: Wait until text in WebElement changes

python,selenium,selenium-webdriver

You need to apply the Explicit Wait concept. E.g. wait for an element to become visible: wait = WebDriverWait(driver, 10) wait.until(EC.visibility_of_element_located((By.CLASS_NAME, 'searchbox'))) Here, it would wait up to 10 seconds checking the visibility of the element every 500 ms. There is a set of built-in Expected Conditions to wait for...

webdriver C# - click this element with XPath position?

c#,selenium,xpath,webdriver

Shouldn't you be using: river.FindElement(By.XPath("//td[4]/a")).Click(); ? And if you have similiar Problems. You can use the Console in the developer tools of Chrome and write like this: $x("YOUR XPATH HERE") This will result in your element. If that's not the case, then your Xpath is wrong. Edit: If you want...

How to parse Selenium driver elements?

python,parsing,selenium,selenium-webdriver,web-scraping

find_elements_by_css_selector() would return you a list of WebElement instances. Each web element has a number of methods and attributes available. For example, to get a inner text of the element, use .text: for element in driver.find_elements_by_css_selector("div.flightbox"): print(element.text) You can also make a context-specific search to find other elements inside the...

Loop through downloading files using selenium in Python

python,selenium,selenium-webdriver,web-scraping,python-3.4

You need to pass the filename into the XPath expression: filename = driver.find_element_by_xpath('//a[contains(text(), "{filename}")]'.format(filename=f)) Though, an easier location technique here would be "by partial link text": for f in fname: filename = driver.find_element_by_partial_link_text(f) filename.click() ...

Upload file - Protractor

javascript,selenium,testing,protractor,end-to-end

The common and the most realistic way to upload the file via protractor/selenium is to send keys to the file input and avoid opening the upload file dialog which you cannot control: var uploadInput = element(by.css("input[type=file]")); uploadInput.sendKeys("path/to/file"); ...

How to write xpath in selenium webdriver for below HTML expressions?

selenium

Try these For 1 //a[text()='Life Insurance'] For 2 //span[text()='Apply now'] ...

Is it possible to save an adobe pdf file using selenium web driver and one click build Jenkins

java,pdf,selenium,jenkins

This works with Firefox: Change the Firefox profile used by Selenium (better to create a dedicated profile as described here) via Tools -> Settings -> Applications and change action of file type PDF to "Save file". In that case the window asking to open file or save will not show...

selenium exceptions.NoSuchElementException:

python,selenium,webdriver

The xpath you've provided doesn't point to a field to input data into, in fact it's actually pointing to the column header. That's why you weren't able to input data into it. Please try the below xpath to fill the name and age in the first row in the passenger...

Return html code of dynamic page using selenium

python,python-2.7,selenium,selenium-webdriver,web-scraping

You need to explicitly wait for the search results to appear before getting the page source: from selenium import webdriver from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC wd = webdriver.Firefox() wd.get("https://www.leforem.be/particuliers/offres-emploi-recherche-par-criteres.html?exParfullText=&exPar_search_=true& exParGeographyEdi=true") wd.switch_to.frame("cible") wait = WebDriverWait(wd, 10)...

Webdriver C# -Click second linktext not first

c#,selenium,webdriver

Use this: //get the list of elements which has same linkText List<IWebElement> list = driver.findElements(By.partialLinkText("Play")); //Click on each element by iterating the loop foreach (IWebElement element in all) { element.click(); } ...

Selenium catch popup on close browser

java,selenium,browser

Instead of using driver.quit() to close the browser, closing it using the Actions object may work for you. This is another way to close the browser using the keyboard shortcuts. Actions act = new Actions(driver); act.sendKeys(Keys.chord(Keys.CONTROL+"w")).perform(); Or, if there are multiple tabs opened in driver window: act.sendKeys(Keys.chord(Keys.CONTROL,Keys.SHIFT+"w")).perform(); ...

Checking element existence on the page with WebDriver findElements().isEmpty method

java,selenium,selenium-webdriver

isEmpty() is actually from the Java List class, as findElements() returns a List of WebElements.

Difference between ancestor and ancestor-or-self

xslt,selenium,xpath,selenium-webdriver

Ancestor and Ancestor-or-self are the XPath Axes. An axis is a node-set relative to the current node. The ancestor axis selects all the ancestors, i.e. parent, grandparent, etc of the current node whereas the ancestor-or-self selects all the ancestors, i.e. parent, grandparent, etc. of the current node and the current...

Java Selenium - Can't seem to select an element

java,selenium,xpath,hidden

Do you get any exceptions thrown? if the element is not visible then a NoSuchElementException will be thrown. Other then that, i would suggest making your xpath more readable, something like the following: String emailAddress = driver.findElement(By.xpath("//span[@class='email']")).getText(); ...

Python AttributeError in Testing Goat

python,unit-testing,selenium

The setup method should be called setUp(), the tear down method - tearDown(): class new_visitor_test(unittest.TestCase): def setUp(self): self.browser = webdriver.Firefox() def tearDown(self): self.browser.quit() def test_can_start_a_list_and_retrieve_it_later(self): self.browser.get('http://localhost:8000') self.assertIn('To-Do', self.browser.title) self.fail('Finish the test!') The methods are actually named correctly in the book....

selenium webdriver - xpath locator not working if element's text contains Unicode Characters

selenium,xpath,unicode,selenium-webdriver,webdriver

Am I missing something here? Yes, I think so: <div class="menuitem-content">Français</div> the "a" is missing driver.findelement(By.XPath("//div[text()='Françis']")); EDIT: At least in a Java environment Webdriver can handle Unicode. this works for me (driver in this case being an instance of FirefoxDriver): driver.get("https://fr.wikipedia.org/wiki/Mot%C3%B6rhead"); WebElement we = driver.findElement(By.xpath("//h1[contains(., Motörhead)]")); System.out.println(driver.getTitle() + "...

Python Selenium - Login error

python,selenium

Check these lines from your code: Line number 15 email = input('Enter your Email ID : ') Line number 17 email = driver.find_element_by_id('Email') Line number 18 email.send_keys(email) So you are assigning your email string to the variable name 'email' and then again assigning the 'webelement' into the same variable name...

Eclipse Selenium Facebook login issue (new page email) driver.findElement(By.id(“email”)).sendKeys(“”); Java

java,eclipse,email,selenium,facebook-login

Since its opening in a different popup you need to first switch to that window (popup) before doing any operation. Try to first get the window object of the popup and then Switch to the window the try to write the email. Below code will help to find the window....

Selenium can't seem to find and click a button on website? - Python

python,selenium,selenium-webdriver,find,element

First of all, using "layout-oriented" or "design-oriented" classes like btn-standard-lrg and btn-white is a bad practice. Instead, there is a convenient locator "by link text", use it: load_more = driver.find_element_by_link_text("LOAD MORE") Note how readable and simple it is. You may also need to wait until the "Load More" button would...

Selenium - get all children divs but not grandchildren

python,html,parsing,selenium,selenium-webdriver

Here is a way to find the direct div children of the div with class name "main_div": driver.find_elements_by_xpath('//div[@class="main_div"]/div') The key here is the use of a single slash which would make the search inside the "main_div" non-recursive finding only direct div children. Or, with a CSS selector: driver.find_elements_by_css_selector("div.main_div > div")...

Python Selenium selecting div class

python,selenium

You are mixing class and xpath locators in an unsupported way! Either of the following will work: driver.find_element_by_xpath("//div[contains(@class, 'first_name')]") driver.find_element_by_classname("first_name") You might want to consider reading some documentation on XPath, and perhaps Selenium locators in general....

How do I tell Selenium that an Angular controller has “loaded”

javascript,angularjs,selenium

There is a specialized tool for testing AngularJS application - protractor. It is basically a wrapper around WebDriverJS - selenium javascript webdriver. The main benefit of using protractor is that it knows when Angular is settled down and ready. It makes your tests flow in a natural way without having...

Selenium Web Driver : How to map html elements to Java Object.

selenium,webdriver,mapping

//Get all the mobile phones links into a list before sorting List<WebElement> mobilelinks=driver.findElements(("locator")); Map maps = new LinkedHashMap();//use linked hash map as it preserves the insertion order for(int i=0;i<mobilelinks.size();i++){ //store the name and price as key value pair in map maps.put("mobilelinks.get(i).getAttribute('name')","mobilelinks.get(i).getAttribute('price')" ); } /*sort the map based on keys(names) store...

Not able to locate the dropdown value using selenium webdriver

java,selenium,selenium-webdriver

First, you have numerous mix up of different kind of waits which should not be done. To find an element and check it's existence the explicit wait works most of the case. Mixing up thread.sleep and implicit wait will give you some really bad performance of test execution Second, finding...

Is there a different way to use methods of another class? [on hold]

java,selenium

If you want to call a method located in the RegistrationPage class you usually need to have an instance of it so the compiler knows which clickOn method you are calling. You can do this without an instance by making the method static and then you can call RegistrationPage.clickOn, but...

Adding a public class to click using xpath with Java Selenium

java,selenium,xpath

You are passing a String: ClickByXpath(driver, "/html/body/div/div[3]/form/div[2]/div[2]/div[1]/div[1]/div[3]/div/div[3]/div/input[1]"); But you method signature says that you should pass a String Array: public static void ClickByXpath(WebDriver [] driverUsed , String[] XPath_to_click) Same problem with your driver! If you change the signature and remove the Arrays, you should be good: public static void ClickByXpath(WebDriver...

Selecting elements by ng-model attribute with selenium-webdriver

ruby,angularjs,selenium,selenium-webdriver

Use find_element() with :css: driver.find_element(:css, 'input[ng-model="MyModel"]') ...

CSS Selector-How to locate Parent Element

selenium,selenium-webdriver,css-selectors,webdriver

Referring to the Is there a CSS parent selector? topic, there is no parent selector in CSS. Leave the "getting the parent" part to the XPath: WebElement we = dr.findElement(By.cssSelector("div[id='gf-BIG']")); WebElement parent = we.findElement(By.xpath("..")); ...

Should I use ids to locate elements?

angularjs,selenium,protractor,end-to-end,e2e-testing

The general rule is to use IDs whenever possible assuming they are unique across the DOM and not dynamically generated. Quoting Jim Holmes: Whenever possible, use ID attributes. If the page is valid HTML, then IDs are unique on the page. They're extraordinarily fast for resolution in every browser, and...

How to get selected option using Selenium WebDriver with Python?

python,selenium,selenium-webdriver,selecteditem,selected

This is something that selenium makes it easy to deal with - the Select class: from selenium.webdriver.support.select import Select select = Select(driver.find_element_by_id('FCenter')) selected_option = select.first_selected_option print selected_option.text ...

When starting Nightwatch with Grunt, the website server is not started

javascript,node.js,selenium,gruntjs,nightwatch.js

you can give grunt-express-server a try and start the server before running the test, for example: npm install grunt-express-server --save-dev and modify the gruntfile: grunt.loadNpmTasks('grunt-express-server'); grunt.initConfig({ express: { options: { // Override defaults here }, dev: { options: { script: 'app.js' } }... // and finally, in the test task,...

Protractor, Done and Expect, why do we need wait?

selenium,selenium-webdriver,jasmine,protractor

You assume that the click promise would get resolved after the url is changed but since you are testing a non-angular page and you turned off synchronization it gets resolved immediately. You should wait for the url to change yourself: var urlChanged = function(expectedUrl) { return function() { return browser.getCurrentUrl().then(function(url)...

XPath for child element

selenium,xpath

//div[contains(concat(' ',@class,' '), ' A ')]//div[contains(concat(' ',@class,' '), ' B ')][1] ...

Find element by class name

python,parsing,selenium,selenium-webdriver,css-selectors

Just let selenium know you don't want the element having ng-hide class with the help of not negation pseudo class: p.p1.transfer strong.ng-binding:not(.ng-hide) ...

Scrapy not entering parse method

python,selenium,web-scraping,web-crawler,scrapy

Your parse(self, response): method is not part of the jobSpider class. If you look at the Scrapy documentation you'll see that the parse method needs to be a method of your spider class. from selenium.webdriver.support.wait import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC from selenium import...

Unable to select text boxes in selenium webdriver through XPath?

selenium,xpath

Change expression so //input[@type='text' and not(@disabled ='disabled')] ...

close and open browser -selenium C# Visual studio

c#,selenium,browser,close

You cannot do that. close will close the lastly opened browser instance. The difference between Close() and Quit() in C# is that the Quit() calls IDisposbile internally and release all the resources used internally which will close and free up all the processes. Coming back to your problem, if you...

Selenium C# Element Not Found Taking a Long Time

c#,unit-testing,selenium,selenium-webdriver

You can try to change the Timeout wait time at the beginning of your test. // In C# you can use ChromeDriver driver = new ChromeDriver("Path to Driver"); driver.Manage().Timeouts().ImplicitlyWait(new Timespan(0,0,2)); This should now wait for 2 seconds for an element to appear before failing. You can set this value to...

Selenium WebDriver: unable to locate element inside iframe using TinyMCE editor

java,selenium,iframe,selenium-webdriver

According to the html the selector to identify the iframe is incorrect. I am using a cssSelector that will allow you to identify the iframe with partial id match. Why do not you try this? driver.switchTo().frame(driver.findElement(By.cssSelector("iframe[id$='_composeEditor_ifr']"))); d̶r̶i̶v̶e̶r̶.̶s̶w̶i̶t̶c̶h̶T̶o̶(̶)̶.̶f̶r̶a̶m̶e̶(̶d̶r̶i̶v̶e̶r̶.̶f̶i̶n̶d̶E̶l̶e̶m̶e̶n̶t̶(̶B̶y̶.̶i̶d̶(̶"̶t̶i̶n̶y̶m̶c̶e̶"̶)̶)̶)̶;̶ driver.findElement(By.id("tinymce")).clear();...

Multi user file property Selenium

java,selenium,junit,webdriver,automated-tests

So we should start browser 2 times and it'll login as Test1 - Abc123 and Test2 - Abc123. In short you will need to get the (Login) comma separated string from the properties file, split it and keep it in a list. Use it in a for loop. List<String>...

Parsing html using Selenium - class name contains spaces

python,html,parsing,selenium,text

The p element has two classes: p0 and ng-binding. Try this selector: find_element_by_css_selector('p.p0.ng-binding') ...

Getting value from div which contains exact string using Selenium IDE

selenium,selenium-ide

From your question, it seems that you want to be able to store the column value based on the number you input. The best way to do this would be <tr> <td>storeText</td> <td>css=div:contains("1")+[class=col_Val]</td> <td>value</td> </tr> Which will store the column value located immediately after the div containing the value you...

Not able to click ExtJS Dropdown button and select list elements - Selenium Webdriver Java

java,selenium,testing,extjs,selenium-webdriver

Try using explicit wait with more precise selectors. By css = By.cssSelector("[placeholder='Please Select a Customer...']"); By option = By.xpath("//li[@role='option'][text()='Customer 2']"); WebDriverWait wait = new WebDriverWait(driver, 10); //Click the dropdown to populate the list WebElement dropdown = wait.until(ExpectedConditions.presenceOfElementLocated(css)); dropdown.click(); //Click the option. Notice the xpath is using the text of the...

Junit parameterized testing ,a different thought

java,selenium,junit

You could use a different call to JUnitCore and implement your own custom computer. The custom computer can generate a parameterized runner if your test class is annotated with your own annotation: @Retention(RetentionPolicy.RUNTIME) public @interface CustomParameterized {} Like so: @CustomParameterized public class Example { private String arg; public Example(String arg){...

Execute javascript within webpage with selenium WebDriver

java,javascript,html,selenium,webdriver

First of all you shouldn't execute javascript using WebDriver unless you really have no other option. Why doesn't the submit work? what did you try? In my experience sometimes click doesn't trigger form submission, so instead you use submit on the form element. Note that if you submit on a...

How to map browser dialog using capybara/selenium

ruby,selenium,capybara

Where possible, you should try to avoid using the underlying driver directly. By using Capybara's API, you would be (in theory) in a better position if you want to change driver's and there are driver API differences. From Capyabara's project page, the way to handle modal dialogs is: In drivers...

Value attribute of a text box retains old value even after new value has been keyed in

java,selenium,selenium-webdriver,webdriver

Because Selenium WebDriver executes so quickly, when you are updating the input value, your getAttribute("value") method is executing before your input gets a chance to update. In your BasePage you need a waitFor boolean protected void waitFor(BooleanCondition condition) { waitFor(condition, "(none)"); } And in your Object page you need to...

How to select a text from the autocomplete textbox using selenium

java,selenium,selenium-webdriver,browser-automation

you can do like this i have used google home page auto suggest as an example public class AutoSelection { public static void main(String[] args) { // TODO Auto-generated method stub WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get("http://www.google.com"); driver.findElement(By.name("q")).sendKeys("mahatama gandhi"); List<WebElement> autoSuggest = driver.findElements(By .xpath("//div[@class='sbqs_c']")); // verify the size...