This is my full code if I will send link for you that would not work for you please run this code help me to fix it guys your 2 answers not helps for me thanks for your support
also you need to create " form_data.txt" inside you project and at this words to form_data.txt
Mark Couwell Erkek 29 07 1988 Pasport I-AG 266556
from ast import Return, Try
from asyncio.windows_events import NULL
from codecs import getencoder
from distutils.command.sdist import sdist
from lib2to3.pgen2 import driver
from operator import and_
from pickle import TRUE
from select import select
import time
from selenium import webdriver
from selenium.webdriver.support.ui import Select
from selenium.webdriver.remote.webelement import WebElement
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
class Project:
def __init__(self) -> None:
self.driver = webdriver.Chrome('chromedriver.exe')
self.main()
def find_the_place_path(self):
# firstly I will get the all path tags
all_place_in_path = self.driver.find_elements_by_tag_name("path")
# title of my path tag is "gat: 1"
for place in all_place_in_path:
print(place.get_attribute('title'))
if place.get_attribute('title') == "gat: 3":
print(" girdim ")
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//*[name()='svg']//*[name()='g' and @class='coupe']//*[name()='path' and @fill-rule='nonzero']"))).click()
time.sleep(10)
#wait = WebDriverWait(driver, 10)
#wait.until(EC.element_to_be_clickable((By.XPATH, "//*[name()='path'][@title='gat: 3']"))).click()
break
def find_the_place_rect(self ):
all_place_in_rect = self.driver.find_elements_by_tag_name("rect")
for place in all_place_in_rect:
print(place.get_attribute('title'))
if place.get_attribute('title') == "gat: 1":
self.driver.findElement(By.xpath ("//*[local-name()='svg' and @id='45']/*[localname()='path']"));
if place.get_attribute('title') == "gat: 2":
print("2 A girdim ")
btn = self.driver.find_element_by_xpath("//*[local-name()='svg' and @id='45']/*[localname()='path']")
btn.click()
break
if place.get_attribute('title') == "gat: 3":
print("3 E girdim")
def input_data(self):
data=open("form_data.txt","r")
for line in data:
count = 0
data.readline()[count]
words=line.split()
print(words)
if words:
first_name = words[0]
last_name = words[1]
gender = words[2]
bday = words[3]
bmoth = words[4]
byear = words[5]
document_type = words[6]
document_snumber = words[7]
document_number = words[8]
count += 1
time.sleep(3)
phone = self.driver.find_element_by_id("phone").send_keys('61260799')
print(phone)
jyns = Select(self.driver.find_element_by_id("jyns"))
jyns.select_by_visible_text(gender)
client_last_name = self.driver.find_element_by_id('lastname').send_keys(last_name)
client_name = self.driver.find_element_by_id('name').send_keys(first_name)
buyer_mail = self.driver.find_element_by_id("email").send_keys("welbekowallanur@gmail.com")
# WebDriverWait(self.driver, 3).until(EC.presence_of_element_located((By.ID, 'passport')))
passport = Select(self.driver.find_element_by_id("passport"))
passport.select_by_visible_text(document_type)
WebDriverWait(self.driver, 3).until(EC.presence_of_element_located((By.CLASS_NAME, 'passport_code_b')))
elements = self.driver.find_elements_by_css_selector('div.first > div.slide > div.info_r > div.wrap > ul > li > div > div.passport_code_b > div:nth-child(1)')
pass_region = elements[0]
passport_region = Select(pass_region.find_element_by_id("passport"))
passport_region.select_by_visible_text(document_snumber)
passport_code = self.driver.find_element_by_id('code').send_keys(document_number)
day = Select(self.driver.find_element_by_id("bday"))
day.select_by_visible_text(bday)
month = Select(self.driver.find_element_by_id("bmonth"))
month.select_by_visible_text(bmoth + " - Iýul")
year = Select(self.driver.find_element_by_id("byear"))
year.select_by_visible_text(byear)
try:
covid = self.driver.find_element_by_id("kepilnama").send_keys("321")
except:
print("Covid 19 NULL")
time.sleep(3)
choose_place_btn = self.driver.find_element_by_xpath("/html/body/div[4]/div[3]/div[4]/div/button")
choose_place_btn.click()
time.sleep(2)
self.find_the_place_path()
#self.payment()
def main(self):
self.driver.get("https://railway.gov.tm/")
self.driver.maximize_window()
select = Select(self.driver.find_element_by_id("one_way"))
self.driver.execute_script("document.getElementById('one_way').style.display = 'block';")
from_where = select.select_by_visible_text("Aşgabat")
#self.driver.execute_script("document.getElementById('dropdown-content').setAttribute('style', 'display: block');")
select = Select(self.driver.find_element_by_id("two_way"))
self.driver.execute_script("document.getElementById('two_way').style.display = 'block';")
to_where = select.select_by_visible_text("Daşoguz")
self.driver.execute_script("document.getElementById('search_date').setAttribute('data-value', '2022-07-29');")
time.sleep(1)
btn = self.driver.find_element(by=By.XPATH, value="/html/body/div[4]/div[2]/div/div/div/div/a").click()
time.sleep(2)
#change_class = self.driver.find_element(by=By.XPATH, value="/html/body/div[4]/div[3]/div[3]/div/ul/li/div[1]/div[3]/ul/li")
#self.driver.execute_script("arguments[0].setAttribute('class', 'seat_1')", change_class)
self.check_ticken()
def check_ticken(self):
li = self.driver.find_elements_by_tag_name("li")
for l in li:
print(l.get_attribute('class'))
if l.get_attribute("class") == "seat_1 ":
print("1 - nji")
seat = self.driver.find_element(by=By.XPATH, value="/html/body/div[4]/div[3]/div[3]/div/ul/li/div[1]/div[3]/ul/li").click()
self.input_data()
if l.get_attribute("class") == "seat_ ":
print("2 - nji")
self.main()
self.driver.refresh()
def payment(self):
card_number = "9931020202020202"
card_holder = "ALLANUR WELBEKOW"
cvc = "999"
card_input = self.driver.find_element_by_xpath("//*[@id='pan_visible']").send_keys(card_number)
d_month_select = Select(self.driver.find_element_by_id("month"))
d_month_selected = d_month_select.select_by_visible_text("Июль")
d_year_select = Select(self.driver.find_element_by_id("year"))
d_year_selected =d_month_select.select_by_visible_text("2035")
card_holder_fill = self.driver.find_element_by_xpath("//*[@id='iTEXT']").send_keys(card_holder)
cvc_fill = self.driver.find_element_by_xpath("//*[@id='iCVC']").send_keys(cvc)
if __name__=="__main__":
pr = Project()