How to find the element through Selenium

selenium find element by xpath python
how to get all the elements in a page using selenium webdriver
find element by xpath selenium java
selenium find element by class java
selenium find element by css selector
selenium find element by attribute
find element by value selenium python
selenium find element by text

I am using Selenium with PHP WebDriver. I am trying to click on a link in the navbar, which appears in the HTML as follows:

<li class=""><a href="javascript:;" showpage="cards"><i class="zzdi zzdi-closed-caption zzdi-hx-fw"></i> User Cards</a></li>

I am trying to select the element then click it. However, when I try using xpath as follows:

//a[@showpage="cards"]

or

//*[@showpage="cards"]

I get the following error:

no such element: Unable to locate element: {"method":"xpath","selector":"/*[@showpage="cards"]"} (Session info: chrome=70.0.3538.110) (Driver info: chromedriver=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d),platform=Linux 4.15.0-43-generic x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 24 milliseconds For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html Build info: version: '3.4.0', revision: 'unknown', time: 'unknown' System info: host: 'ubuntu', ip: '127.0.1.1', os.name: 'Linux', os.arch: 'amd64', os.version: '4.15.0-43-generic', java.version: '1.8.0_191' Driver info: org.openqa.selenium.chrome.ChromeDriver Capabilities [{mobileEmulationEnabled=false, hasTouchScreen=false, platform=LINUX, acceptSslCerts=false, goog:chromeOptions={debuggerAddress=localhost:43431}, acceptInsecureCerts=false, webStorageEnabled=true, browserName=chrome, takesScreenshot=true, javascriptEnabled=true, setWindowRect=true, unexpectedAlertBehaviour=, applicationCacheEnabled=false, rotatable=false, networkConnectionEnabled=false, chrome={chromedriverVersion=2.43.600233 (523efee95e3d68b8719b3a1c83051aa63aa6b10d), userDataDir=/tmp/.org.chromium.Chromium.Teyqo7}, takesHeapSnapshot=true, pageLoadStrategy=normal, databaseEnabled=false, handlesAlerts=true, version=70.0.3538.110, browserConnectionEnabled=false, nativeEvents=true, locationContextEnabled=true, cssSelectorsEnabled=true}] Session ID: 367080a50b61c75a8c16a17b954a5972 *** Element info: {Using=xpath, value=/*[@showpage="cards"]}

Any help on how to use xpath or how to use any other selection method that would enable me to click on the link would be appreciated.

You might need to wait for element to be able to click it:

$driver->wait()->until(
  WebDriverExpectedCondition::elementToBeClickable(WebDriverBy::xpath('//a[@showpage="cards"]')))->click();

Find Element and FindElements in Selenium : Differences , This article is for anyone who just started using Selenium and wants to know the best ways to find elements. The key here is to find the most  A Practical Guide for Finding Elements with Selenium 1) Find Element By ID Always the first choice. In order to get the ID of your element, you just have to right click on 2) Find Element By Name Just as good as ID, but you won't encounter it as often as you'd expect. Elements from forms 3)

A Practical Guide for Finding Elements with Selenium, Selenium provides the following methods to locate elements in a page: from selenium.webdriver.common.by import By driver.find_element(By.XPATH  Find Element in Selenium using By Strategy. Finding elements in Selenium WebDriver is done by using the findElement(By.locator()) method. The findElement methods take a locator or query object called ‘By’. In the eclipse code window type driver.findElement(By dot), Eclipse IntelliSense will populate the list of different locators.

Apparently, due to differences in windows size (my machine vs. the virtual screen used by Selenium), the navbar wasn't displayed and therefore the element could not be found.

Found it out while doing a workaround - getting all elements with "a" tag, then iterating through them. Only after clicking on an extra button to make the navbar displayed, the element could be found.

4. Locating Elements, Selenium Webdriver provides the following techniques for locating the web elements. Click here to Go Back to main Selenium Python tutorial. 1. Locate Element by  Find Elements in Selenium WebDriver: Difference between “FindElement” and “FindElements” Find Element Returns the first matching web element if multiple web elements are discovered by the locator

How to Locate Elements using Selenium Python with Examples, Now let's understand how to find an element using a name. Find by Name. This method is similar to Find By Id except the driver will try to locate  Finding Web Elements X Y Coordinates Using Selenium: Any web element has its own position on page known as x y coordinates. x y coordinates of a web element is measured in x and y pixels. x pixels means the horizontal position of an element on a page from the left side and y pixels means the vertical position of an element on a page from the top.

How to Find Elements in Selenium WebDriver, Locating one element. One of the most fundamental techniques to learn when using WebDriver is how to find elements on  The method below follows: public String verifyTextAssert (By by) { return driver.findElement (by).getText (); } In the TratOsFatRoamPage class I created the getNuPu method that calls the verifyTextAssert method and passes the xpath to this method and should return the found value.

Locating elements :: Documentation for Selenium, Selenium Find element by text which is used to locate a web element using its text value. The text value can be fully matched or partially  Step 1: Locate/inspect the web element (“Sign in” button in our case) and notice that the HTML tag is “input”, the attribute is type and value of type attribute are “submit” and all of them together make a reference to the “Sign in” button. Verify the locator value

Comments
  • This error happens as an exception when attempting to do driver->findElement. The script doesn't even reach the wait() part...
  • Thanks, but I'm afraid that didn't work. I get "PHP Fatal error: Uncaught Facebook\WebDriver\Exception\TimeOutException in /var/www/html/wioc/sdk/ext/vendor/facebook/webdriver/lib/WebDriverWait.php:84" after the command. When I do a getPageSource I can clearly see that link appearing in the HTML.
  • @Idan , Can you check whether link located inside an <iframe>
  • No iframes on the page and the link is visible when I access the site manually. Thanks!