Python Selenium manipulating table-style element instances

Source: Internet
Author: User
Tags xpath

Most of the time, the layout on the page is in tabular form, such as the following

This type of Web page in the automation of the headache, need a lot of judgment, below for example, here to Shenzhen entry-Exit page for example, http://yysl.sz3e.com/wsyysq/select_sldw_zbs.jsp

For example, we need to click on any one of the Saturday can be an appointment time, how to write it.

First of all we want to analyze, this is also the first step to write a program, the manual operation of the logical extraction, and then form a program

1, first determine the date in the list, find the Saturday column

2, and then from the found column to determine the time of the appointment of the point

The basic idea is this, to see the 1th, how to extract the table-style date and time?

Use Firepath to see

So you can use current to find all the Id,xpath://label[@class = ' current ']


How do you figure out a list of data?

As you can see from the HTML, this is a standard form of a form

You can use the following methods to locate a column of data

//tbody[@id = ' timeline ']/tr/td[1] where 1 represents the 1th column, the corresponding column can be taken out as needed

The basic code is as follows:

All_data=browser.find_elements (By.xpath,"//label[@class = ' current ']")#Select all date element pairs likeRowall=[rowall.text forRowallinchAll_data]#take out the corresponding date elementrowindex=[rowall.index (i) forIinchRowallifU'Saturday' inchI#Get column" "determine if Saturday can be scheduled, no 2s refresh" " whileTrue:tds=browser.find_elements (By.xpath,"//tbody[@id = ' timeline ']/tr/td[%d]"% (rowindex[0]+1))    if[TD forTdinchTdsif "Reservations Available" inchTd.text]: Break    Else: Browser.find_element_by_xpath ("//span[@receivepointsid = ' 440307000000 ')"). Click () time.sleep (2).....

Python Selenium manipulating table-style element instances

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.