0

I'm trying to write a program that automates the whole process of joining a webex meeting. However after having read the documentation on how to get an element through id, Xpath etc nothing seems to work.

from selenium import webdriver

PATH = "C:\Program Files (x86)\chromedriver.exe"
driver = webdriver.Chrome(PATH)

driver.get("link")

element = driver.find_element_by_ #?#

element.send_keys("some text")

HTML:

Site

I guess my question is: how do I acquire the appropriate element in order to add my name?

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
George
  • 1
  • Does this answer your question? [Selenium Finding elements by class name in python](https://stackoverflow.com/questions/30002313/selenium-finding-elements-by-class-name-in-python) – Chris Dec 28 '20 at 12:58

4 Answers4

0

Use the class name

browser.find_element_by_class_name("style-input-2nuAK undefined")
coderoftheday
  • 1,987
  • 4
  • 7
  • 21
  • element.send_keys("sometext") AttributeError: 'list' object has no attribute 'send_keys I seem to be getting this bug any ideas? here is the code from selenium import webdriver PATH = "C:\Program Files (x86)\chromedriver.exe" driver = webdriver.Chrome(PATH) driver.get("link") element = driver.find_elements_by_class_name("style-input-2nuAK undefined") element.send_keys("sometext") – George Dec 28 '20 at 15:21
  • You're using `find_elements_by_class_name`, which returns a list of web elements, so you cannot use the `send_keys` method there. Change that to `find_element_by_class_name` (singular). – MikeCode Dec 28 '20 at 17:43
  • @MikeCode 'Traceback (most recent call last): File "C:\Users\Γιώργος\Desktop\Wx.py", line 9, in element = driver.find_element_by_class_name('style-input-2nuAK undefined') File "C:\Users\Γιώργος\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 564, in find_element_by_class_name return self.find_element(by=By.CLASS_NAME, value=name) File "C:\Users\Γιώργος\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element 'value': value})['value']' – George Dec 28 '20 at 18:24
  • File "C:\Users\Γιώργος\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute self.error_handler.check_response(response) File "C:\Users\Γιώργος\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response raise exception_class(message, screen, stacktrace) – George Dec 28 '20 at 18:24
  • It's not able to find web-element with `.style-input-2nuAK undefined` class. There could be two issues for this. 1) Your locator is incorrect. 2) Your code is trying to access element before it being loaded into DOM. Try introducing `time.sleep()` before you that grab element. – MikeCode Dec 28 '20 at 18:44
  • @George if the issue is due to the delay in element rendering. Introduce implicit wait `driver.implicitly_wait(5)` and that should solve the issue for all elements. – MikeCode Dec 28 '20 at 18:59
  • @MikeCode from selenium import webdriver PATH = "C:\Program Files (x86)\chromedriver.exe" driver = webdriver.Chrome(PATH) driver.implicitly_wait(10) driver.get("link") driver.find_element_by_class_name("style-input-2nuAK undefined") element.send_keys("sometext") I suppose you mean this, however im still getting the same error any other ideas? – George Dec 28 '20 at 19:46
  • @George I have posted my solution code. Try with that. – MikeCode Dec 28 '20 at 19:58
0

To send a character sequence to the element you can use either of the following Locator Strategies:

  • Using css_selector:

    driver.find_element_by_css_selector("input.undefined[placeholder='Your full name']").send_keys("George")
    
  • Using xpath:

    driver.find_element_by_xpath("//input[contains(@class, 'undefined') and @placeholder='Your full name']").send_keys("George")
    

Ideally, to send a character sequence to the element you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using CSS_SELECTOR:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "input.undefined[placeholder='Your full name']"))).send_keys("George")
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//input[contains(@class, 'undefined') and @placeholder='Your full name']"))).send_keys("George")
    
  • Note: You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Do i need to intall anything else ? – George Dec 28 '20 at 15:24
  • I don't think you need to install anything unless you are using Nuget packages. With Nuget packages you may need `SeleniumExtras.WaitHelpers` package. – undetected Selenium Dec 28 '20 at 17:51
  • Traceback (most recent call last): File "C:\Users\Γιώργος\Desktop\Wx.py", line 12, in WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//inut[contains(@class, 'undefined') and @placeholder='Your full name']"))).send_keys("George") File "C:\Users\Γιώργος\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\support\wait.py", line 80, in until raise TimeoutException(message, screen, stacktrace) selenium.common.exceptions.TimeoutException: Message: Im getting this bug any ideas on what im doing wrong ? – George Dec 28 '20 at 17:57
  • from selenium import webdriver PATH = "C:\Program Files (x86)\chromedriver.exe" driver = webdriver.Chrome(PATH) driver.get('link') element = driver.find_elements_by_class_name('style-input-2nuAK undefined') element.send_keys('sometext') Also tried this but then i get this error : Traceback (most recent call last): File "C:\Users\Γιώργος\Desktop\Wx.py", line 10, in element.send_keys('sometext') AttributeError: 'list' object has no attribute 'send_keys' – George Dec 28 '20 at 17:59
0

CSS for the element

input[placeholder="Your email address"]

driver.find_element_by_css_selector("input[placeholder="Your email address"]").send_keys("George")

XPath for the element

//input[@placeholder="Your email address"]

driver.find_element_by_xpath("//input[@placeholder="Your email address"]").send_keys("George")
Janesh Kodikara
  • 1,670
  • 1
  • 12
  • 23
0

Try with below code.I have tested this using publicly available login page

driver = webdriver.Chrome()
driver.implicitly_wait(5)
driver.get("https://signin.webex.com/signin")
email_input = driver.find_element_by_xpath("//div[@class='el-input']/input")
email_input.clear()
email_input.send_keys('test@test.com')
driver.find_element_by_xpath("//button[@class='el-button next el-button--primary']").click()
driver.find_element_by_xpath("//span[contains(text(),'meetingsamer37.webex.com')]").click()
driver.find_element_by_id("continue-button").click()
password_input = driver.find_element_by_xpath("//input[@aria-label='Password']")
password_input.send_keys('test')
driver.find_element_by_xpath("//button[@class='el-button next el-button--primary']").click()
MikeCode
  • 91
  • 11
  • 1
    Apparently i needed to add driver.switch_to.frame("pbui_iframe") and then locating the element by xpath. Thank you for taking the time to explain – George Dec 28 '20 at 21:06