Struggling to find a unique identifier for a password field? I'm experimenting with attributes and quotations, trying to figure out how to handle multiple sets. Is it necessary to mix single and double quotes when dealing with three sets?
(Could a different approach, like using descendants/children in a path-like manner, be more effective?)
The website I'm currently working on can be found here.
This is the code snippet I've worked on so far:
import os
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
# create driver object and launch the webpage
driver = webdriver.Chrome()
wait = WebDriverWait(driver, 20)
driver.get("https://myibd.investors.com/secure/signin.aspx?eurl=https://marketsmith.investors.com/")
# switch to the iframe we need
driver.switch_to.frame(driver.find_element_by_css_selector("iframe[id = 'signin-iframe']"))
# variable for username field
username_field = driver.find_element_by_css_selector("input[name='username'][data-gigya-placeholder='Email']")
# variable for password field
password_field = driver.find_element_by_css_selector()
I want to experiment with these two tags & values:
gigya-expression:data-gigya-placeholder="screenset.translations['PASSWORD_132128826476804690_PLACEHOLDER']"
gigya-expression:aria-label="screenset.translations['PASSWORD_132128826476804690_PLACEHOLDER']"
Edit 1
Tried new methods that didn't work:
1.) Attempted to escape quotes within the value using backslashes as suggested below.
password_field = driver.find_element_by_css_selector("input[gigya-expression:data-gigya-placeholder='\"screenset.translations[\'PASSWORD_132128826476804690_PLACEHOLDER\']\"']")
2.) Explored using escape characters for single and double quotes, as discussed in this article.
password_field = driver.find_element_by_css_selector("input[gigya-expression:data-gigya-placeholder='"screenset.translations['PASSWORD_132128826476804690_PLACEHOLDER']"']")
Edit 2
Using XPath as a workaround
Although CSS posed challenges, xpath provided a solution. Inspecting the target element and copying the XPath by right-clicking on the HTML was helpful.
Copied XPath:
//*[@id="gigya-login-form"]/div[2]/div[3]/div[2]/input
Python code implementation:
password_field = driver.find_element_by_xpath("//*[@id='gigya-login-form']/div[2]/div[3]/div[2]/input")