Reputation: 17
<button name="main" type="submit" class="mainfont">
التسجيل</button>
XPath:
/html/body/table/tbody/tr[2]/td/table/tbody/tr/td/table[1]/tbody/tr/td[18]/font/button
Full XPath:
/html/body/table/tbody/tr[2]/td/table/tbody/tr/td/table[1]/tbody/tr/td[18]/font/button
How can I click this button in selenium? I have tried different methods but none worked, some notes:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains
#
path = "XXXX"
driver = webdriver.Chrome(path)
#
driver.get("XXXX")
driver.maximize_window()
#
login1 = driver.find_element_by_name("liun")
login1.send_keys("XXXX")
time.sleep(2)
login1.send_keys(Keys.RETURN)
#
try:
element1 = WebDriverWait(driver, 100).until(
EC.presence_of_element_located((By.title_is, "XXXX"))
)
finally:
login2 = driver.find_element_by_name("gsw")
login2.send_keys("XXXX")
login2.send_keys(Keys.RETURN)
pass
# THE CODE BELOW DOES NOT WORK
html = '''
<button name="main" type="submit" class="mainfont">\nالتسجيل</button>
'''
driver.get("data:text/html;charset=utf-8," + html)
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='\nالتسجيل']"))).click()
Upvotes: 1
Views: 46
Reputation: 29382
I made the HTML
that you've provided and could create a xpath
with text and clicked
on it using Explicit waits
:
driver = webdriver.Chrome(driver_path)
driver.maximize_window()
html = '''
<button name="main" type="submit" class="mainfont">التسجيل</button>
'''
driver.get("data:text/html;charset=utf-8," + html)
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[text()='التسجيل']"))).click()
print('Done successfully clicking')
Imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
Upvotes: 1