using getHtmlSource in Selenium after following a link on the initial page - php

I opened a page and am following a couple of links with the click() method.
$this->selenium->open("test.html");
$this->selenium->click("link=testlink1");
$this->selenium->waitForPageToLoad("10000");
$this->selenium->click("link=testlink2");
$this->selenium->getHtmlSource();
Now I want to get the HTML source of the current page that I am on, but getHtmlSource seems to only get the source of the initial page from the open() call.
How do I get the HTML source of the page from 'testlink2'? The last link I followed and the current page I'm on.

Ok, so it appears if you do this, things work.
$link2 = $this->selenium->click("link=testlink2");
$this->selenium->getHtmlSource($link2);
Now, I'm running into a problem that getHtmlSource doesn't seem to returning everything. Looks like it has some sort of buffer limit :(
Also, it doesn't look like this technique will work on links to pages that require authentication. So if you login first, then click on some links, it doesn't work.

getHtmlSource should return the current page's HTML source. Your example might need an additional waitForPageToLoad between clicking the link and getting the page source.

Related

php how to pass an anchor in the command line

I need to pass parameters and an anchor in a php program to make sure the cursor is positioned at the last place it was in the page when it returns.
program.php?ID=123&ID2=456#777
ID=123
ID2=456
html anchor is #777
Can someone tell me how to make this work? Since it isn't working the way I'm doing it now. Thanks
The browser will not send the anchor to web server.
So PHP can't get the anchor from url.
maybe you can use javascript to request program.php?ID=123&ID2=456&anchor=777, then you can get the anchor by $_GET['anchor'].
Sorry for my bad english (愒o愒).
If you want force the cursor to the position.
this code will redirect to http://website.com/page.php#anchor and the broswer will auto cursor the position.
<?php
header("location: http://website.com/page.php#anchor");
exit;
warning: take care about header function, there is the manual header function
If the current page is the same as the redirect page, above the code will infinite redirect and the browser will throw error. So you have to write some logic, make it redirect when you want. Or just write two different page, one to show content, other one redirect to content page with anchor.
But I still think it is better to do that by JavaScript.

Make a link redirect to the same page

I've created a page with an article. On top of that there's a title. If people try to click this title I want them to be redirected to the same page.
Like this: https://gyazo.com/74350b4fe91c670c4101449ee1c928a4 If I click on the article it just refreshes the page.
I can't do this manually for every article because I'm using a script.
The code I've written looks like this:
echo ' <h1 class="entry-title">'.$row['postTitle'].'</h1>';
As you can see I wrote
<a href="/">
and that's will not redirect me / refresh the page i'm viewing.
This is how it looks for me: https://gyazo.com/8a15ae274d8a7240b07100395460568d
as you can see it does not redirect me to the same page when i click the title.
How can I do this?
To make your custom PHP blog post template be able to display a title link that points back to the page, one way is to make use of your $row[.... variable.
Provided that,
your URLS will look like your screenshots, such as http://localhost/viewpost.php?id=8 when running locally and for example http://www.yourwebsite.com/viewpost.php?id=8 when online
you know how to refer to the post's id that is used in the ...viewpost.php?id=8, for example $row['postID']
you don't yet have any variable or means to refer to your current domain http://localhost when local or http://www.yourwebsite.com when online
Then, I recommend a two-part approach:
Somewhere at the top of your code, or perhaps in an include you might use for such code-reuse purposes, define for example $host:
$host='http://' . $_SERVER['SERVER_NAME'];
Then, for your actual title link::
echo ' <h1 class="entry-title">' . $row['postTitle'] . '</h1>';
Explanation
Separated HTML from the concatenation dots . with spaces, to be easier to read, as well as to support any helper programs such as fmt that you might use for wrapping long lines, so they have spaces to use for wrapping lines.
Uses PHP's predefined $_SERVER variable's SERVER_NAME , which, combined with the http://, the $host will be http://localhost when local and http://www.yourwebsite.com when online.
Define $host as a variable once at the top of the page, because it is clearer that way and likely you will have a use for it elsewhere on the page, so this helps avoid having to repeat yourself writing 'http://'.$_SERVER['SERVER_NAME'] everywhere else you may need to start forming the absolute URL
$host is then combined with the pattern for the rest of the URL, to assemble the absolute URL
Absolute URL is helpful so that if a user saves your article to their computer, then later clicks the title link on their locally saved article, the user can still correctly reach the original online page
As the article author, setting a link this way also means it can serve as a permalink, which helps with search engine optimization (SEO)
Please use # in href attribute! that will redirect you on the same page.
Problem solved. I used
echo '<h1>'.$row['postTitle'].'</h1>';
Thank you everyone.

how can I make a page opening only into the iframe and not if it's called directly?

The content generate by list.php should be only opened into an iframe tag, on the index.php. But when it's called directly, it should not be possible to open it.
How can I obtain this?
In fact I already adopete this method:
<iframe title="frame" class="iframe" src="http://www.example.com/list.php?type=a&013acd2b6c1368f">[Your browser doesn%27;t support iframes]</iframe>
which works fine, thus if the file is called without the arguments ,it redirects to the index.
BUT if you call it directly in this way http://www.example.com/list.php?type=a&013acd2b6c1368f the content appears at full page. While I want that, being outside the tag , it redirects to Index.php
Is there any way please?
I'm sorry to any one.
After have written this message, I finally found the answer here and with small adaption it worked out perfectly.
I didn't find this post before.
Answer to my question

Issue with formulating a url php / html

I am trying to formulate a link to another page in my directory. It can either be done in the php code or the html. However for some strange reason, and only on this page, everytime i generate a url to a new page, the url generated is the page i am on + the url i want to go to.
For example, if i am on mysite.php and formulate a link to go to purchase.php then the generated url is mysite.php/purchase.php
Does anyone know why this might be?
<h1>Success</h1>
Link text
<?php
...
...
?>
this is essentially all i have with an echo saying hi! . What happens is, if i am currently on home.php the above url becomes path/home.php/page.php
You should create url for /purchase.php instead of purchase.php.
You can read more about what's the difference in here.

php open dynamic link in new window with iframe

Hello I am trying to figure out how to make it so when someone clicks a link on my search results it will open in a new window and in the new window have an iframe that displays the url. I am not sure how to go about doing this. I have
$row['url']
that displays the url for each result to use.
To be more specific I am trying to do what filestube does. I like the feature a lot and would like to use something like it on my site. Here is an example url to show you want I mean http://www.filestube.com/5a4c10249bd9fce003e9/go.html
when the link is clicked on filestube it will open a page like this. I have seen lots of sites do this but filestube is what pops in my head right now. Can anyone provide me with a code example or try to explain how to do this? thanks.
You need to redirect to a URL inside of your application, example my_url.php and post to it in parameters the URL you want to show. Than in that script, load an iFrame with that URL.
Example of my_url.php?url=http://www.google.ca:
<div>You Header</div>
<iframe src="<?php $_GET['url']"></iframe>
<div>Your Footer</div>
The link should point to another PHP page. Something like this.
http://www.google.com
In your open-link.php, write your iframe code.
<iframe src="<?=$_GET['url']?>"></iframe>
Assuming you have PHP file named external.php
Make that PHP file accept a $_GET parameter.
Pass the URL as a param
Use that URL to point the iframe in that PHP file to whatever URL is passed

Categories