Using selenium, how do i click dropdown menu to get to login page ofhttps://www.phptravels.net/

I have the following website that i would like to automate: https://www.phptravels.net/

i would like to click on "My Account" to reach "register" and "login".

currently, i am doing it manually by navigating:

https://www.phptravels.net/demo/login

https://www.phptravels.net/demo/register

I am using python 3.7 for this task

I have tried locate it using Xpath, with no luck. it cannot find the items, nor click them.

[![<a href="javascript:void(0);" data-toggle="dropdown" class="dropdown-toggle go-text-right"><i class="icon_set_1_icon-70 go-right"></i> My Account <b class="lightcaret mt-2 go-left"></b></a>][1]][1]

please see attached image for that

NavbarTopOnIE.java, handle with dropdown menu on Phptravels.net website using selenium I have some big problem with handle with dropdown menu on I wrote this test, but it doesn't work and I don't have idea how to do it logger.info("Clicked on Login link"); It's always a good practice to use css selector over xpath. You need to specify more info to the a tag saying which value to select. So you need to use something like : driver. findElement (By. xpath ("//a[@title='Selenium']")). click (); In this way you actually are looking for the search box first and then you look for the suggestion drop down by clicking on the element and its done. You get your drop

The link My Account is available inside an iframe name called preview-frame To access the element you need to switch the iframe first.

Induce WebDriverWait and frame_to_be_available_and_switch_to_it()

Induce WebDriverWait and element_to_be_clickable()

Try below code.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium import webdriver

driver=webdriver.Chrome()
driver.get("https://www.phptravels.net/")
#Switch to Iframe first
WebDriverWait(driver,15).until(EC.frame_to_be_available_and_switch_to_it((By.NAME,"preview-frame")))
#Click on My Account
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='container']//li[@id='li_myaccount']/a[contains(.,'My Account')]"))).click()
#To Click on Login
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='container']//ul[@class='dropdown-menu']//a[contains(.,'Login')]"))).click()

To click on Sign UP you need to add following code.

#To Click on Sign Up
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,"//div[@class='container']//ul[@class='dropdown-menu']//a[contains(.,'Sign Up')]"))).click() 

Browser Snapshot:

How to handle with dropdown menu on Phptravels.net website , Here are the best sites you can use to run Selenium webdriver tests. to bring in a list of demo websites where you can practice Selenium webdriver online, With these demo sites, you can automate a login page, online registration forms, Since you are now getting curious to know about the online sites to test Selenium  Right click on the drop-down menu on the sample web page and select Inspect Element It will launch a window containing all the specific codes involved in the development of the drop-down menu. Take a note of its id attribute.

Danny

How to select an option from drop-down menu?

WebDriver provides three ways to select an option from the drop-down menu.

  1. selectByIndex use

    dropdown.selectByIndex(5);

  2. selectByValue

    dropdown.selectByValue("Database");

  3. selectByVisibleText

    dropdown.selectByVisibleText("Database Testing");

Hope to help na kub.

7 Websites to Practice Selenium Webdriver Online, Go to Environment variables, and put webdriver path in PATH variable. To do so Click on Advanced System Settings which will open a pop up box. Click on We will be scraping data from http://www.phptravels.net/ for our example. This is a test This will lead you to the login page of this website. Now  To select a drop-down menu option value with Selenium (Python), firstly you need to import the Select class and then you need to create the instance of Select class. After completing these two steps you will need to create the instance of Select class, you can perform select methods on that instance to select an option from the dropdown list.

Here you have to click on my account first and then click on either login or signup by finding 2 xpath i.e one for my account, second for login and signup. I have no idea about python but here is the xpath:

1) Myaccount : (.//li[@id='li_myaccount'])[2]/a/b

2) Login : (.//ul[@class='dropdown-menu']/li/a)[3] or

signup : (.//ul[@class='dropdown-menu']/li/a)[4]

If you know how to use List<> you can get the list for login and signup option and click on it using index.

Hope it works for you. Thank you.

Web scraping with Selenium, In this section, you will learn how to handle drop-downs in Selenium WebDriver. WebDriver provides three ways to select an option from the drop-down menu. 1​. After that we have to initialize Chrome driver using ChromeDriver Class. Right click on the drop-down menu on the sample web page and select Inspect  Hello, I'm trying to click on a drop-down button in selenium pyChrome, but nothing seems to work for me by clicking on the inspect option in the button I get: Hide/Show<paper-dropdown-menu no-label-fl

Selenium WebDriver Handling Drop-Downs, QTP and Selenium are the most used tools in the market for software automation testing. In order to develop Selenium RC or WebDriver scripts, users have to ensure that id = 'menu']/div[3]/a"); Thread.sleep(2500); // Wait for page load // Click on of each of the locator methods with the help of https://www.calculator.​net  In this tutorial, we will learn how to handle Drop Down and Multiple Select Operations. Select Option from Drop-Down Box. Before we can control drop-down boxes, we must do following two things: Import the package org.openqa.selenium.support.ui.Select; Instantiate the drop-down box as a "Select" object in WebDriver

Selenium - Quick Guide, I am going to show you how to write tests for a login page in 3 different ways: 1. without Alex Siminiuc, enjoys writing about Selenium test automation and labradors If you follow them, you will never have incomplete test cases in your automation suite: Now you need to perform action such enter text or click on buttons. Stack Exchange network consists of 177 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

How do I write Script in selenium using Java for a login , Double click in Selenium. Double click action in Selenium web driver can be done using Actions class. Actions class is a predefined class in Selenium web driver used to perform multiple keyboard and mouse operations such as Right Click, Drag and Drop, etc.

Comments
  • The page content is wrapped in an iframe: <iframe class="full-screen-preview__frame" src="https://phptravels.net/demo" name="preview-frame" frameborder="0" noresize="noresize" data-view="fullScreenPreview" allow=</iframe>. Dealing with frames is a common selenium gotcha FWIW. Here's a link to unofficial documentation: selenium-python.readthedocs.io/… Good luck!
  • Possible duplicate of Select iframe using Python + Selenium
  • I still couldnt do it. can you please write what you meant?
  • Not sure what you mean by "I still couldnt do it.". If you looking for someone to write your code for you, then it looks like people have done that...
  • Why you need xpath or css selector to identify the iframe when you can easily identify by its name? Sorry Your answer does not give any better resolution.
  • @KunduK Not sure what exactly you meant by ...better resolution..., however it seems to be a beginners question. If you have any doubt on locators feel free to raise a new question with your new requirement.
  • hi, thank you for the answer. but i cannot make it work. it still cannot find the element. i am trying via xpath.