1

I'm currently working with Selenium and Python to create a script that helps with booking free spots on a website for internships so you don't have to check it all the time.

I found the clickable element but now I don't know how to add the condition. I would like to make a text attribute the condition, which is under a td tag below the "button" but don't know how. It shows how many places are available to the total amount of places (x/y, so I'd make it 1/ ). Is it even possible?

Maybe I could do it by the green color but I can't find where it is anchored in the HTML document

browser.get('https://www.pj-portal.de/index_hro.php?PAGE_ID=101')

delay = 2


browser.find_elements_by_xpath("//*[starts-with(text(),'1/')]")
print("found")
Liste1 = browser.find_elements_by_xpath("//*[starts-with(text(),'1/')]")
print(len(Liste1))

B = browser.find_element_by_xpath("//img[@src='images  /wunsch_setzen_button.svg']")
B.click()
print("button")

Screenshot of Webpage

Part of HTML

<img class="aktion_tertial_wunsch_setzen " data-pj_traineeship_tertial_id="166037"
      data-pj_general_traineeship_id="8487" data-changetype="24"  
      src="images/wunsch_setzen_button.svg" alt="+" title="Wunsch">
<td class="hinweise_leer  verfuegbar  buchungsphase "> </td>
<td class=" tertial_verfuegbarkeit verfuegbar  buchungsphase  ">1/3</td>

Thanks you in advance

1 Answer 1

1

Did you try to use position () method in xpath ? for example:

// xpath using position() targeting the first element starts-with(text(),'1/'
res= browser.find_elements_by_xpath("//*[starts-with(text(),'1/')][position()=1]")
res[0].click()
Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the reply! It tells me this error: "AttributeError: 'list' object has no attribute 'click' ". Which list is it refering to, do you know?
I figured it out with B = browser.find_element_by_xpath("//*[starts-with(text(),'1/')]/preceding-sibling::td[2]/child::img") It will find 2 results, have you got an idea how to adress the second result?
that means it did not return a callable element but a list may be you should add something like "result[0].click()"
Is it ok for you now @Krischk?
Somehow it does not click the element nor does it give me an error, the script just runs thorugh and nothing happens
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.