1

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

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Danny Kaminski
  • 191
  • 2
  • 15
  • 2
    The page content is wrapped in an iframe: ` – orde Sep 20 '19 at 17:43
  • Possible duplicate of [Select iframe using Python + Selenium](https://stackoverflow.com/questions/7534622/select-iframe-using-python-selenium) – orde Sep 20 '19 at 17:46
  • I still couldnt do it. can you please write what you meant? – Danny Kaminski Sep 20 '19 at 20:16
  • 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... – orde Sep 20 '19 at 22:05

4 Answers4

1

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:

enter image description here

KunduK
  • 32,888
  • 5
  • 17
  • 41
1

To login in to Costco.com through the url https://www.costcobusinessdelivery.com/LogonForm?URL=%2f as the the desired elements are within an <iframe> so you have to:

  • Induce WebDriverWait for the desired frame to be available and switch to it.
  • Induce WebDriverWait for the desired element to be clickable.
  • You can use the following solution:

    • css_selector:

      driver.get("https://www.phptravels.net/")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe.full-screen-preview__frame")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "nav li#li_myaccount>a"))).click()
      
    • xpath:

      driver.get("https://www.phptravels.net/")
      WebDriverWait(driver, 10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@class='full-screen-preview__frame']")))
      WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//nav//li[@id='li_myaccount']/a"))).click()
      
  • Browser Snapshot:

phptravels_login_menu

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • 1
    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 Sep 21 '19 at 07:56
  • @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. – undetected Selenium Sep 23 '19 at 06:23
0

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.

superup
  • 1,765
  • 13
  • 12
0

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.

Pratik
  • 357
  • 1
  • 9